How to Remove Query Strings From Static Resources

”Remove query strings from static resources” a common statement which you find while checking the loading time of your site in GTmetrix or any other related tool. We all know that Google is now using page speed to rank pages in their search results, so you must have a closer look at the all the aspects which are slowing down your site.

You can use Google Page Speed, Pingdom Tool or GTmetrix to find out the parameters which are affecting the speed of your site and take action to rectify those issues. Today in this post, we will take remove query strings from static resources a very common parameter which affects loading speed of a site.

 

Remove query strings from static resources

You can’t cache a link with a “?” in its URL. The query string is a method used by developers of WordPress tools to pass the content values or to carry the version detail.

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. Different experts have a different solution to achieve this. Let’s look at some of the solutions with proven track record.

#1. 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 );

Code Source

 

#2. Secondly, if you are using W3 Total Cache plugin on your WordPress site, go to Browser cache settings and uncheck “Prevent caching of objects after settings change” and save your settings. This should make sure to remove the query strings from static resources served from your domain.

W3 Total Cache Browser Cache

#3 Remove Query Strings From Static Resources

 If the above-mentioned methods don’t work for you, there is a really useful plugin which helps you to remove query strings from static resources.

This is a very simple plugin, just install and active the plugin and that’s all. There are no additional settings which you need to take care of to remove query strings from static resources.

Download Plugin

Remove-Query-Strings

This plugin is already downloaded more than 25000 times with five-star rating, so I’m sure this plugin worked for most of the users.

#4 Query Strings Remover

Query Strings Remover is another WordPress plugin that can help you to remove query strings from your static resources like CSS and JavaScript files.

This is a very simple plugin to use, just install the plugin and activate. After the activation doesn’t forget to clear the cache so that you can check how this plugin improves the overall performance of your site.

Download Plugin

Query Strings Remover

#5 Speed Booster Pack

Speed Booster Pack is a very useful WordPress plugin that can help you to do a lot of things to improve the performance of your site and make it quick as well as SEO friendly.

Other than removing query strings from static resources, this plugin does a lot of things such as

  • Eliminate external render-blocking javascript and CSS in above-the-fold content
  • Moves scripts to the footer to improve page loading speed
  • Loads CSS asynchronously to render your page more quickly and get a higher score on the major speed testing services.
  • Minify and inline all CSS styles and move them to the footer to eliminate external render-blocking CSS and optimize CSS delivery.
  • Lazy loads images to improve page load times and save bandwidth.
  • Changes image compression level to keep file sizes smaller.
Download Plugin

Speed Booster Pack

Conclusion

The speed of your site is not only important from the search engine’s point of view but also from the user’s experience point of view. 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.

Create an SEO friendly site with Divi and drive huge traffic & revenue.

divi-popular-multipurpose-theme

How to Remove Query Strings From Static Resources
4.2 (84%) 25 votes

Know Everything About WordPress
Best Products in Your Inbox

Subscribe to our mailing list and we will surprise you with amazing WordPress freebies

Jupitar Theme
  • I haven’t tried #1. Thanks for the tip. I do use #3 and it works well, but if #1 means one less plugin, great.

  • Himanshu Shrivastava

    Yeah… #1 code is working fine :) better is to use code instead of plugin..

  • Good to know that Himanshu, thanks for stopping by

  • Chinmay Rajyaguru

    Yes! #1 is the best.
    I’ve little bit modified. You may check it: https://gist.github.com/chinmayrajyaguru/f0af7192c23a83ff01acac120ef06fac

  • Sebastian

    Option Number 1 is working fine.

  • Thanks for the article. I’ll add Speed Booster Pack in my all websites :)

  • the first code worked for me. thanks.

  • conor

    Thanks Dhiraj. If you are interested we made a free plugin too that can accept custom args to remove only the query strings that you wish, maybe you will find it interesting:

    https://wordpress.org/plugins/remove-query-strings-littlebizzy/

  • Charlie Brown

    Thank you bro!!

  • Hope you can help with a question. I’m not a programmer, just trying to learn how to resolve all this issues on my website by trial and error :) I’m using wordpress with a soledad theme – I see I have different functions.php files in my folders, one of the theme and another general (I guess) for wordpress. Which do I put this syntax in, or should it go in both. I don’t want to put more plugins so hope you can help.

  • Stiaan van Moerkerken

    Thank you!!!!! This saved my life!

  • Thank you!

  • I tried the W3 Total Cache and it got a little better. I tried the Remove Query Strings From Static Resources and WP Disable with no luck. I am still having tons of scrips from an *external site* where I had originally uploaded some images. I don’t know how these scripts work. I’m also getting the message from Pingdom “Leverage Browser Caching” with the same external site. I’m a designer, not a programmer and my site takes 10 seconds to load. I don’t know how to disconnect from this external site. Any clues, ideas or recommendations? Many thanks!

  • Hi Rachel,

    10 seconds is too long, there could many reasons other than the query string from external site. You need to look at the theme you are using as well as the hosting, these two are very important factors as far as the loading speed is concerned.

  • Thank you Dhiraj. This just worked like a charm!

  • Thanks for this, worked really well!

  • You are welcome Giacomo, keep visiting SourceWP :)

  • John Cleary

    Worked fantastically well on my site. Thanks!
    FYI W3TC has an option to remove query strings which I ticked/checked and it worked a treat without the additional plugin :)

Know Everything About WordPress
Best Products in Your Inbox

Subscribe to our mailing list and we will surprise you with amazing WordPress freebies