How To Increase Website Speed By Removing Query Strings From Static Resources

Website loading time is an important part of a website. It determines the user experience and the overall ranking on search engines. CSS & Javascript are static resources and are always present when you load a website. Query strings comes attached with CSS & Javascript. Query Strings are the URLs which has “&” ot “?” in them. Some servers and proxy servers are unable to cache query strings, even if a cache-control:public header is present. These strings prevent caching of CSS & Javascripts. Leveraging Browser Caching of Static Resources like CSS and JavaScript plays an important role in page loading time. In this tutorial, you will learn how you can increase the website speed by removing query strings from static resources.

How To Increase Website Speed By Removing Query Strings From Static Resources

Prerequisites

  • Domain name (example.com)
  • Admin Dashboard
  • FTP client (Filezilla, cyberduck)
  • Text Editor (Notepad, Sublime Text)

Step 1:

Login into your WordPress admin dashboard using your admin credentials. Hover over Appearance on the left side menu and click Editor.

How To Increase Website Speed By Removing Query Strings From Static Resources

Step 2:

On the right side, locate functions.php and click on it. You can also access functions.php file using the FTP client. It is located inside /public_html/wp-content/themes/theme-name. Use your favorite text editor make changes in the functions.php file.

How To Increase Website Speed By Removing Query Strings From Static Resources

Step 3:

Now, you need to add the following code into your functions.php file.

//* 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 );

Step 4:

There are various plugins which can help remove the query strings from static resources. Some of the popular plugins are Remove Query Strings From Static Resources, W3 Total Cache, Query Strings Remover.

  • Remove Query Strings From Static Resources: Query Strings from Static Resources can be removed using a plugin called Remove Query Strings From Static Resources. This method is specially for beginners, who don’t want to go inside the themes folder and edit the functions.php file. You need to install the plugin and activate it. There is no settings for configurations, so just activate the plugin and it will remove the strings.
  • W3 Total Cache:  W3 Total Cache plugin gives an option to remove query strings from static resources. You only need to Uncheck an option in the settings and it will remove query strings from the URLs. Go to Browser Cache tool tab and find Prevent caching of objects after settings change option. Uncheck it from General Settings and click on Save Settings button. Now Empty all Cache. Check your page loading time and see the difference.
  • Query Strings Remover: This is another WordPress plugin called Query Strings Remover. Download this plugin from WordPress plugin repository for free. Install and Activate it. There is no configuration or setting page. Activate it and you are complete. Delete all the cache and check your website on Pingdom. All the Query Strings will be removed automatically from static resources.

Conclusion:

This is how you can increase the speed of a website by removing query strings from static resources by making some changes in the functions.php  file.

Check out these top 3 WordPress hosting services:

HostArmada
£1.98 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
IONOS
£0.79 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
£2.30 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Add Custom CSS to Your WordPress Website in Different Ways

This how-to guide will have three different ways to add custom CSS to a WordPres
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Migrate Your Website From Joomla to WordPress

The tutorial will have a step by step explanation about migrating a website from
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

How to Move WordPress Theme's JavaScript to the Footer for Better Performance

This is a guide to edit the WordPress Theme's functions.php file for moving the
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Edit the CSS for your WordPress Site Using the cPanel Hosting Control Panel

As you know, the design of a WordPress website is controlled by
4 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top