Remove query strings from static resources in WordPress

Remove query strings from static resources in WordPress

Remove query strings from static resources is a common warning which you find while checking the loading time of your site in GTmetrix or any other related tool. Google uses page speed as one of it’s ranking factors, so you must have a closer look the all the aspects which are slowing down your site.

What does this warning mean?

Query string parameters are used to pass information to the web server. The web server can user this information to adapt the content. For example image.jpg?size=200 could be used to ask the server for a 200px thumbnail

As a query string usually means that the content is dinamic, web browsers don’t cache resources with parameters in its URL

Why do developers add version query strings to static resources?

Developers usually use version query strings to avoid browser cache. Picture this: if a theme used on a site loads static a style.css file, when a visitor enter the site his browser will load and cache that file. If the theme is updated and the css file changes, a returning visitor could still see the outdated style.css file from its browser cache.

To prevent this, developers add a query string to the static file like this:

/css/style.css?ver=1.2.3

Even if this can improve the user’s experience, it can also impact the site’s performance. And, guess what? WordPress do this automatically to many of its own static resources.

How to remove query strings from static resources

Now, the question is how to remove query strings from static resources to make sure that it is not affecting the loading time of your site. Depending on you experience level, there are two roads you can take:

Option 1: Using code

Solution number one is to use the code given below, open functions.php folder of your theme put code given below in the file save it, clear cache and check if it works.

function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Source

Option 2: Using Machete

Open Machete optimization module tab, select the checkbox next to the “version” option under “Header cleanup” and click the “change options” at the end of the page. That is all.

Remove query strings from static resources in WordPress using Machete

Conclusion

The speed of your site is important from the search engine’s point of view, but it also affects the user’s experience. No one would like to visit a site which takes minutes to load a page. Make sure you look at all the aspects which are responsible for slowing down your site and rectify.

Remove query strings from static resources, an issue which can be resolved and once it is resolved it will definitely bring in a positive effect to your site.