Faster page load speed is what matters if you have an online presence. There are several services available online that provide you the performance of your page. The one recommendation that you might have seen is “Serve resources from consistent URL”.
This article elaborates on the meaning of recommendation given by tools like Pingdom, GTmetrix, or Google PageSpeed Insights while describing the ways to tackle the problem.
Why this recommendation appears?
There are several files associated with the website such as CSS, JS, images, and many more. Whenever the visitor opens your website the visitor’s browser requests from the server to send the files. For each file, a request is sent which means HTTP request is generated. So, as the number of HTTP requests increases the page loading time also increases. Since both of them are directly proportional to each other.
Now, sometimes what happens is that a resource is available through multiple hostnames and domains. Consequently, each time the page is loaded the resources gets called and downloaded multiple times from each of the existing URLs.
This puts a bad effect on SEO and page load timings.
How similar resource URL occurs?
There may be several reasons behind it:
- When the identical resources are shared between two or more subdomains or subdirectories of the same website or between dissimilar linked websites.
- When the same external resources or libraries are used by two or more plugins.
- It may result from incorrect indirect.
- It may also result from misconfiguration in CDN settings or bugs in the theme.
How to fix the problem?
#Method 1: Move
Often inconsistent URLs are created by resources such as images, which are shared by multiple subdomains or linked sites.
For example: If your website example.com shares an image with the site division subsite.example.com. This will create two paths for the same file.
/media/image.png
/subsite/media/image.png
Solution 1 - Fix Serve Resources from a Consistent URL with Moving Method
To fix the problem, serve the file from a single hostname, instead of hosting it from the same website and its subdivision. That is, there is a need to host it on. To illustrate, example.com link to it from subsite.example.com
This solution also brings benefit when two separate domains are used and works efficiently when they are linked. Although there is a need for additional DNS lookups every time the advantage of caching makes it worthy. It is noteworthy that a DNS lookup will be anyway required due to the linking of two sites.
You may also like to read:- How to Enable Keep-Alive? What is it, its Methods and Benefits
#Method 2: Rewrite
Duplicate resources are also generated when sometimes is used to speed up the website. This happens by the way in which plugins and themes handle static resources.
Normally all the media files are moved to the CDN by editing all the static resources URLs manually by using a plugin or creating a C name.
While this works seamlessly, but your plugin or theme can pull some files, for instance, the site’s logo into the site’s code and out of the media library.
Therefore, the same files are served from your domain (files pulled into theme settings) and CDN (the media library).
Solution 2 - Fix Serve Resources from a Consistent URL with Rewrite Method
To fix this problem, change the file path in the theme’s file. This is done to point to the file on the CDN. This may vary from theme to theme.
The logo settings are mostly available in the file names header.php. The search line defines the logo path and matches it with the CDN resource URL. Use the child theme to make the necessary changes in the theme file.
To ensure all the links are consistent it is better to use a plugin Better Search and Replace.
#Method 3: Redirect
When the site exists at www.newsite.com and newsite.com or you have hosted different versions of the site on two separate addresses. This results in duplicate resources. There may be some practical reason for doing so, but in reality, you end up having two websites, one that exists at the root of the domain and other hosted at the subdomain www.
Consequently, having two websites that are deeply connected but end up with duplicate results.
Solution 3 - Fix Serve Resources from a Consistent URL with Redirect Method
Here you are advised to select the preferred version and then apply the 301 redirects. The 301 redirect ensures that browser and search engines will skip all other versions and go to the preferred version of resources and pages.
One can also use 302 redirects, which is used when one’s website is still developing and changing. This redirect instructs that resources have temporarily been moved.
#Method 4: Canonical Tag
The issue can also be fixed by using canonical tags. But it should not be preferred first, unless 301 and 302 serves the purpose. These tags does not eliminate the problem but only instructs the search engines to prefer certain version.
One should use these tags only when the 301 and 302 cannot be applied.
Solution 3 - Fix Serve Resources from a Consistent URL with Canonical Tag
Add the link to the preferred resource with rel = canonical attribute in the code. This can be used in a similar way across domains.
#Method 4: Plugins
There are times when the usage of multiple resources results in a warning of consistent URLs. This happens because multiple plugins share resources or a single plugin adds a resource to the original URL.
Solution 4 - Fix Serve Resources from a Consistent URL using Plugin
Deactivate one of the plugin which is causing the trouble.
Conclusion
This article discussed all the possible ways in which a consistent URL issue can be fixed to improve the page loading speed.