Should I Locally Host External Files for Better Website Speed?

Your website speed can be affected negatively if it needs to use externally hosted files to function properly. That’s because web browsers will need to spend some time finding those external file locations on the internet using a process called DNS resolution. But this isn’t always true because using some external storage solutions like a CDN can help improve your website speed. You can also use DNS prefetching to minimize the DNS resolution time for the external websites.

Your website needs various assets like CSS, JS, images, etc. to display the website properly to the visitors. But when it comes to storing these files you have two options one is to host the files locally on your web server so that whenever your website needs to use those files it can just use the files from your local server. And the second way is to store the files on a different web server and then linking the file location on your web pages. Then when your website needs those files it can just use the files from the linked external location. You can also use files that already exist on other websites by just linking their location on your website. For instance, if you want to use different fonts on your website, you can just link to externally hosted fonts like Google fonts and then use the fonts on your website.

But in terms of website speed, depending on various scenarios, both of these methods can either help your website load fast or make it load slowly.

How Locally Hosted Files Help with Website Speed?

When we want to visit any website, we just type a domain name in a web browser and press enter. But this isn't how web browsers connect to websites. Web browsers need IP addresses to connect to other computers, in this case, connect to another computer that is hosting the website we are looking for. That's why after receiving a domain name, a web browser first needs to find the IP address associated with the domain name. This process of finding IP addresses associated with domain names is called DNS lookup or DNS resolution. And the time it takes for the DNS resolution to complete is added to the website load time.

So, every time a web browser finds a new domain name, a new DNS resolution takes place and the total website load time increases. However, web browsers don’t need to perform DNS resolution more than once for the same domain name on a website. Therefore, if all the assets required for your website are stored on your web server, then web browsers won't have to go through the DNS resolution process more than once. For instance, after the web browser connects to your website after performing a DNS lookup for your website’s domain name, it will no longer perform DNS lookups when it needs to download additional files like images from your domain name. But if your images are hosted in a different domain, then the browser will need to perform another DNS lookup for that new domain name. And this will increase your website’s load time.

Additionally, when you host your website files locally, you will have additional control over the files. For instance, you can tell web browsers how long they should store your files in their cache memory after they visit your site. This way when someone wants to visit your website for the next time, the browser will be able to load the files from its cache memory. Therefore, the browser won’t have to download the files from your server, which will result in faster load time for repeat visitors.

Also, if you are using any website speed testing tools like PageSpeed Insights, GTMetrix, or others and getting a warning saying leverage browser caching, then you will be able to solve this problem if your files are hosted locally. But if your files are hosted externally where you don’t have any control, you won’t be able to do anything regarding this warning.

How Externally Hosted Files Affect Website Speed?

As discussed in the earlier section, if your website needs to load files from external websites, it will need to go through the DNS resolution process multiple times. So, each of the new domains whose assets are being used on your webpage will add some extra time to your webpage load time because of the extra time taken for each DNS resolution.

Multiple assets from the same external domain won't require more than one DNS resolution process in case of a single page load. So, only the first asset from the external domain will require going through the DNS resolution process and the others will use the first asset's DNS resolution result.

Other than DNS resolution, you will have to be dependent on the performance of the external website. In order for your website to use the files stored on the external website, the files will first be required to be downloaded by the web browsers. But if the external website loads slowly, then the web browser will have to wait for the download to take place before it can fully display your website. This added time will also negatively affect the load time of your website. So, the performance of your site will be dependent on that of the external website.

Additionally, if the external website goes down or if the site removes those files or changes their location, then web browsers won’t be able to download those files, and so depending on the type of contents stored on the external website, your website may not load anything at all.

There is also the issue of not being able to control the caching of the files as discussed in the previous section. Which gets in the way of reducing the load time of your website even further to the repeat visitors.

Therefore, it is always a good idea for your website to keep the use of contents from different domains to a minimum.

Can Hosting Files Externally Help with Website Speed?

Hosting your files externally doesn’t always increase your website load time. Depending on the external source, it can also decrease your website’s load time. The most common example of this is using a CDN or Content Delivery Network. CDNs help reduce your website load time by storing your website files in many data centers all around the world. So, whenever someone wants to visit your website, the CDN will deliver your website files from the data center that is closest to that person. This will make your website load faster to people all around the world.

Generally, you can use a CDN to store and deliver your website’s static files like the images using a subdomain of the CDN provider. You can also change the CDN provider’s subdomain name to one of your subdomains. For instance, if your domain name is then you can use the subdomain to deliver your images from the CDN. Even though web browsers now will need to go through an additional DNS lookup for the subdomain or the subdomain or your CDN provider, your website's total loading speed may actually decrease because of the faster delivery of the images from the CDN.

Also, some external files like Google fonts are already stored and served from CDN so they should load fast from all over the world. However, linking this external file to your website will cause web browsers to go through an additional DNS lookup which will affect your page speed. But you can address this issue using a technique called DNS prefetching which is described in the next section.

How to Reduce the Effect of Files Hosted Externally?

There are many reasons why someone would use files from external websites. For instance, if you want to use an image on your website from a different website, then because of simplicity you can just copy and paste the image link in your website. But if you wanted to host the image to your web server, you will first need to download the image then upload the image on your website and then link the local image to use it in your website.

Therefore, hosting all your website files locally can sometimes be a little difficult and sometimes impossible. So, there might be some files that you will want to use from external websites. But using files from external websites doesn’t have to result in slow load time for your website. Because there are some useful techniques that you can use to reduce the impact of external websites on your website load time.

One thing you can do to reduce the DNS resolution time for the external websites is to use DNS prefetching. DNS prefetching allows web browsers to perform DNS lookup in the idle time. Therefore, the browser will try to find the IP address associated with the external domain names when it is waiting for other tasks to be completed. Therefore, it won’t have to spend extra time resolving external domain names which will make your site load faster.

Also, when you have control over the external provider or if you can choose to go with a provider of your choice, then you can choose to go with the ones that provide CDN for faster file delivery all around the world.

One thing to note here is that DNS resolution generally takes less than a few hundred milliseconds and if the web browser has already visited the external sites recently, then it may already have the IP address for the website cached in its memory. In that case, it won’t have to spend extra time for the DNS resolution to complete. Also, the browser may already have the external files stored in their cache memory if it had to download the files recently for browsing yours or any external website. This might actually happen a lot for external files like Google fonts that are used on many websites.

You can check out this article to know more about how you can reduce DNS lookup time to speed up your website.

How to Locally Host External Files?

As discussed earlier there are benefits that you get by hosting your website files locally. So, if you want to host your website files locally on your web server, then there are different ways you can do that. You already probably know how to upload different files like HTML, CSS, JS, images, etc. to your website using its default systems, file managers, or by using any FTP applications. And then link those files to your webpages whenever you want to use those files. But if you already don’t have those files, then you can download the files from the external website and then upload them to your website and then link them on your website.

If you are using any CMS like WordPress then, you will also find several plugins that will make this process easier for you. For instance, if you are looking to host third party files like fonts and analytics locally on your WordPress website, then you will find different plugins on the WordPress repository that will make the process a lot easier for you.

When You Should Not Host Files Locally?

Even though there are many benefits of locally hosting your website files, there are some situations when you might want to prefer using externally located files. Some of those situations are discussed below.

Mediocre Web Server

If your web server performance isn’t very good, then downloading files from your website will take longer. This will affect how fast web browsers can download your website files and therefore a poor web server will make your website load slow. That’s why if your web server isn’t performing well, then you can consider using files from external servers that perform well.

Reducing Server Load

There might be situations when you want to reduce the load from your website. Maybe your web server resources are very limited that it can’t properly serve many visitors at a time or maybe you want to reduce your web hosting cost or maybe you have some other reasons. Regardless of the reason, if you want to reduce the load from your web server, then you can use externally hosted files in your website.

Lack of CDN

If your website isn’t configured with a CDN, then serving your website to people all over the world may not be very efficient. And so they will experience slow load time for your site. That’s why if you aren’t using a CDN, you can use files from external websites that are using CDN.

Frequently Changing File

You may want to use files from external websites when the files are continuously updated on the external website and you also want your website to reflect that updated information. If that is the case, then you can choose to use the external files by linking them on your website thereby eliminating the need to manually update those files every time they are changed in the external website.

Leave a Reply

Your email address will not be published.