blog posts

Fix the Remove query strings from static resources error in GTmetrix

Another error that you will often encounter during site speed testing is the Remove query strings from static resources error in GTR Metrics. This parameter is for requests that are sent as query strings and include the character ? If I want to point to an example of these requests, I can point to the address of the avatar, which has an expression like ?s=70&d=mm&r=g at the end. Or at the end of JS and CSS files, which will be displayed as VER value. The existence of these Query Strings causes them to not be cached in the sources that have a question mark at the end of their address, and in addition, they will not be cached on the CDN content distribution network and other browsers. So, this issue causes not only the volume of your pages to increase, but also another error “Leave Browser Caching”.

In this tutorial from Hostfa’s knowledge base, going to discuss how to fix the Remove query strings error in GT Metrics. Using this tutorial, you can easily fix this error from your site in different ways.

Remove query strings from static resources error

You must have this question in your mind that what are query strings and why should we use them to increase site speed. As I mentioned above, the existence of query strings causes the desired files to be uncached and loaded from the server every time the user visits the site. For this reason, it increases the loading speed of the site and increases the number of HTTP requests. But on the other hand, the existence of query strings allows developers to update the changes they apply to the files sooner without being cached. That is, when you buy a WordPress theme and an update is released a few days later, as long as the files are cached, the previous users for whom these files were cached will still see the site’s previous appearance.

Fix the Remove query strings from static resources error in gtmetrix

For this reason, it is better to manage the query strings ourselves and update the cached files whenever needed by defining the time interval. In this case, whenever you make an update on the files, you can easily resend the file to the visitor’s browser through the server so that it is updated and not loaded for them in cache mode.

Remove WordPress Remove query strings error

To solve the problem of Remove query strings from static resources in WordPress, there are two solutions in front of you, which include the use of plugins and the use of coding. If you want to use the plugin, just click on the button below and after entering the plugin page plugin installation guide in WordPress , install and activate the plugin on your site After activating the plugin, you don’t need to do anything else, and special menu and settings will not be added to your site. Just leave the plugin activated.

Download Remove Query Strings plugin

In addition, if you use the wp rocket plugin, you can activate this feature in WordPress using the plugin settings. guide Wp Rocket plugin training .

But if you don’t want to use the plugin, you can activate this feature by adding the following piece of code in the function file (functions.php) of your WordPress template. For this purpose, after entering your host, refer to the File Manager menu. Then go to public_html/wp-content/themes. Now enter the template folder that is active on the site and find the functions.php file. Finally, right-click on the file and select Edit option to add the following codes in the right place.

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

After you save the file, this feature will be activated in WordPress and the CSS and JS files will be cached.

Remove Joomla’s Remove query strings error

If you are using Joomla, you can also click on the button below and install the Joomsef plugin on your site to fix the error in Joomla. After installing and activating this plugin, it is possible to delete string queries from Joomla and JS and CSS files will be cached