As a blogger we have a habit of checking loading speed of our blog on tools like GT matrix and Google pagespeed insights. Although it is important to check your blog loading time this way we can know the issues and reduce the loading time of Blog.

Here we are discussing one such issues which is a culprit when it comes to website speed. Moreover you might have visited this page through search engine for the reason that is ”ways to remove query strings from static resources like JavaScript and css”

Here at WPTechian we will cover everything related to query strings in WordPress and most important questions which comes to your mind like ”why we should remove query strings from static resources” and definitely ”how to remove query strings” and what are the effects of removing query strings in WordPress blog.

To start with

Page load time is definitely one of the most important criteria of any popular and good website or blog. Like if your web page load time is less as compared to other competition then definitely you are going to get higher rankings in Google search on any other search engines available. This will increase your organic traffic to your blog.

Apart from this it will enhance your user experience google has announced that they consider website speed as one of the parameters for search rankings. And we can easily see most of the search comes from mobile space this leads to the emergence of amp project. Which is very fast as compared to normal without amp page. That is why website speed is very much relevant to rank you higher in search engines especially Google.

What are query strings in WordPress

Query strings are the links which usually contains “?” or “&” For example

wptechian.com/script.js?ver=1.7

Query strings are mostly similar to CSS and JavaScript files of your blog. Which generally have file version at the end of links.Therefore query string resources all written with “?” or “&”

Proxy servers don’t cache CSS and JavaScript resources with query strings even if you have optimized.

Same applies for content delivery network like keycdn they also don’t cache resources with query string.
The question may arise then ”why we are using query strings” even query strings are known to decrease blog load time. Well to answer this I would say query strings are very much useful because it adds a version and numbering to the file. With the help of this resource files can be distinguished easily. Plus point for all the developers of wordpress.

You can yourself check all the query strings in your website with tools like, GT matrix and pagespeed insights (Google developers) You can find the detailed analysis of your blog through these tool. You can find all the URL with query strings like “?” or “&”

Leverage browser caching is very important when it comes to load time of website as which can cache your static resources like CSS and JavaScript but query strings don’t let cracking of static resources on browsers.

How to remove query strings from static resources

That is why you have to remove query strings from static resources like JavaScript and style sheets. Then only you will be able to enable caching on browsers. After removing these strings you can check your blog load time through GT matrix you will see the difference from before test you have done.

How to remove query strings from static resources

It is not that tough to remove query strings you simply have to add filter hook in your WordPress theme’s functions file. These hooks (add_filter) are used to modify internal strings and data in WordPress.

These are the steps to remove query strings from static resources

Edit the functions.php file from your wordpress theme. Paste the following code which I have given. To the end of your functions.php file. Click on save.
Now you have removed query string.

//* TN - Remove Query String from Static Resources
function remove_css_js_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_css_js_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_css_js_ver', 10, 2 );

Don’t forget to take backup of your blog in case if you are not able to do it correctly you are safe with your blog.

If you are someone who fear to use or add code then they can definitely use plugins to remove query strings from static resources. We don’t recommend to use many plugins as they can slow down your blog. It is always advisable to learn code for small things like this.

You can use plugins if you are newbie or not sure how to code

Plugins to remove query strings from static resources

1.Remove query strings from static resources plugin

This is easiest to use plugin to remove query strings easily. According to the author this plugin will remove query strings from resources inside the HTML head.
As I have specified it’s very much easy to use you just need to install and activate your good to go.

2.W3 total cache

This is the most popular cache plugin out there. This plugin will take care of all the cache tasks easily but there is setting to remove query strings from static resources this is one of those plugin which everybody should use in their blogs.

Conclusion

You will increase speed of your blog if you remove query strings from static resources in files like Java scripts.
If you have got results please share your page speed in the comment section.