Remove Query Strings from Static Resources
You can occasionally optimize your caching by eliminating them. This will also resolve the “Remove query strings from static resources” warning that you may receive in GTMetrix and Pingdom.
Query strings should be removed from static resources.
Remove query strings from static resources
Please keep in mind that query strings are typically used for a specific purpose. WordPress developers utilize versioning on files to get around cache issues. If they release an update and alter style.css from?ver=4.6 to?ver=4.7, for example, it will be viewed as a brand new URL and will not be cached. If you remove the query strings and then update a plugin, the cached version may continue to serve. In rare circumstances, this may cause your site’s front-end to ma lfunction until the cached page expires or the cache is flushed fully.
Query strings are also used in development workflows to organize data.
Query Strings should be removed from static resources.
You can delete query strings in a couple of ways, one with a little code and the other using a WordPress plugin. If you’re delivering your assets through a CDN, this may not be necessary because some CDN providers can cache query strings. Before implementing the following, check with your web host and CDN provider to verify if they can cache query strings. The query strings are cached by the Kinsta CDN.
Code to Remove Query Strings from Static Resources
Using a Plugin to Remove Query Strings from Static Resources 1. Using Code to Remove Query Strings from Static Resources
With a few lines of code, you can simply delete query strings from your assets. Create a child theme and add the following to the functions.php file of your child theme after making a backup of your site.
if(!is admin()) function remove query strings() add filter(‘script loader src’,’remove query strings split’, 15); add filter(‘style loader src’,’remove query strings split’, 15); add filter(‘script loader src’,’remove query strings split’, 15);
$output = preg split(“/(&ver|?ver)/”, $src); function remove query strings split($src)
$output = $output = $output = $output
remove query strings; add action(‘init’,’remove query strings’);
Important: If you don’t do it right, editing the source code of a WordPress theme can ruin your site. If you’re not sure about doing this, talk to a developer first. You might also use the Code Snippets plugin, which is available for free. This plugin will allow you to put the above code to your site without fear of it crashing.
Simply make a new snippet and paste the code above into it. Save the snippet after selecting “Only run on site front-end.” Then your query strings will vanish! To see the changes take effect on the front end, you may need to clear the cache on your WordPress site.
Do you want to discover how we grew our traffic by over 1000%?
Join the 20,000+ people who receive our weekly email with WordPress insider secrets!
Now is the time to subscribe.
code snippet to remove query strings
With Query Strings, you may get rid of the query strings code snippet (Before Code)
Here’s an example of query strings being used to load scripts.
Query strings in requests
Query Strings are not used (After Code)
Here’s an example of a script after query strings have been deleted.
Requests that do not include query strings
2. Using a Plugin, remove the Query String from Static Resources
Using a WordPress performance plugin with this feature built in is an alternative to using code. With the premium Perfmatters plugin (created by a Kinsta team member), you can eliminate query strings from static resources with a single click. It also allows you to simply add other WordPress site optimizations and works in tandem with your current cache plugin.
With the Perfmatters plugin, you can get rid of query strings.
No More Query Strings
In website speed test tools like GTMetrix or Pingdom, you should no longer notice a warning concerning query strings after utilizing either of the following options.
The warning about removing query strings from static resources has been fixed.
Save time, money, and improve site performance by using:
Expert WordPress hosting assistance is available 24 hours a day, 7 days a week.
Integration with Cloudflare Enterprise.
With 29 data centers across the world, we can reach a global audience.
With our built-in Application Performance Monitoring, you can improve your performance.
All of this and more is included in a single plan that includes no long-term obligations, aided migrations, and a 30-day money-back guarantee. Check out our plans or speak with a sales representative to find the ideal plan for you.