If you have tested your site speed using any tools like GTmetrix, Pingdom, etc. you might have noticed this, “Remove query string from static resources“.
So, here I’ll show you how to remove that error.
What are Query Strings?
Query strings are the URLs containing “&” and “?” in it.
Something like this,
Query strings are the URLs that you see containing special characters such as “&” and “?”. The query strings are seen in the scripts and stylesheets.
It causes caching issues and it is important to remove those Query strings. Even CDNs can’t help you if you don’t remove Query Strings from static resources.
You can’t ignore this if you know how important the site speed is. Google loves quality content and the content with quality ranks on Google. But Google looks many other factors while ranking a site. And the speed is one among the top factors in it.
People won’t wait for your site to load, even if your’s is the best content. So, there would be an increase in bounce rate which will affect your site’s ranking in Search Engine.
How to Remove Query String From Static Resources
WordPress users, you can do it in two different ways,
- Using a WordPress plugin
- Manually adding a code in functions.php
#1. Using WordPress Plugin – Remove Query String From Static Resources
Install this plugin on your self-hosted WordPress site and it will remove the query strings. This is a lightweight plugin.
If you are comfortable editing the functions.php of your WordPress site, you can follow the manual method and avoid installing a plugin.
#2. Manually editing functions.php
Open your functions.php and add this at the end of the file.
$parts = explode( ‘?ver’, $src );
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );