How to Remove Query Strings From Static Resources

Shayla Price
Shayla Price

Updated:

Published:

Web page speed on your WordPress website is a key factor in improving the visitor experience. Your customers don’t like waiting for content to appear. In fact, a two-second delay in web page load time can increase bounce rates by 103%

remove-query-strings-from-static-resources

Every second counts when it comes to satisfying your visitors. Query strings in static resources can slow down your website. So, one solution is to remove them to increase your page speed. Let’s walk through how you can make this simple change to your WordPress website.

Grow Your Business With HubSpot's Tools for WordPress Websites

What are the Query Strings in WordPress?

A query string is everything that follows the “?” or “&” in a URL. WordPress developers use query strings to transfer content values or to distinguish files from one another. You can find them in static resources, like JavaScript and CSS files. A query string looks like this:

 

https://yourwebsite.com/wp-includes/js/wp-embed.min.js?ver=3.5.7

Why You Should Remove Query Strings

Query strings aren’t part of the hierarchical path structure to load your web page, and because the query string data is exposed, hackers can compromise your website.

Plus, query strings prevent servers from caching your website. As a result, your page speed slows down. By removing the query string, you improve caching and decrease the page load time.

How to Test Your Website Load Time

Google considers page loading speed when ranking your website. If you suspect (or are just curious) about your website’s speed, there’s an easy way to check it. 

Visit free website performance tools, like PageSpeed Insights, Pingdom, or GTmetrix. On the homepage, add your website address in the empty URL box and press the button next to it to start the test.

Each tool gives you an analysis of your WordPress website. You’ll see a performance score, the actual load time, and recommendations to improve your page speed. For instance, one of the suggestions may be to remove query strings from static resources.

suggestion to remove query strings from static resources

Source: CM Solutionz

When performing your test, don’t be alarmed if your website doesn’t get a perfect score. Your website might contain third-party URLs with query strings. That’s okay. The goal is to remove query strings from static resources loaded from your domain.

Let’s start with the code method. Go to Appearance > Theme Editor in your WordPress dashboard. Then, follow these steps. 

  • Choose your specific theme in the right-hand corner.
  • Select the theme functions (functions.php) under Theme Files on the right-hand side. 
  • Copy and paste this code at the end of the functions.php file.

 

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

  • Click Update File to save your changes.

Don’t feel comfortable editing source code? Try the code-free method below using plugins. 

Plugins to Remove Query Strings From Static Resources

WordPress performance plugins make it easy for you to remove query strings from static resources. With a few clicks, you can improve your website load time.

1. W3 Total Cache

W3 Total Cache is a popular plugin trusted by web developers and web hosts for improving SEO results. To bypass the creation of query strings, you can make changes in the plugin’s settings. 

  • Install and activate the plugin. 
  • Go to the Performance tab on the left side of your dashboard. Click Browser Cache.
  • Uncheck the box next to Prevent caching of objects after settings change.
  • Check the box next to Remove query strings from static resources.
  • Click Save all settings.

W3 Total Cache plugin for removing query strings from static resources

 

2. Hummingbird

It’s difficult to manage every optimization technique for your WordPress website. Luckily, you don't have to with Hummingbird. This plugin scans your website to find out what’s slowing it down and then provides you with a detailed performance report.

  • Install and activate the plugin. 
  • Go to the Hummingbird tab on the left side of your dashboard. 
  • Click Advanced Tools.
  • Under the General tab, click the slider next to Remove query strings from my assets. (It will change from white to blue.)
  • Click Save Changes.

Hummingbird plugin for removing query strings from static resources

 

3. WP Performance Score Booster

WP Performance Score Booster is another free WordPress plugin to improve your page load speed. One user reported a 50% boost in his website speed with the help of this plugin.

  • Install and activate the plugin. 
  • Go to the Settings tab on the left side of your dashboard. 
  • Click WP Performance Score Booster.
  • Click the slider next to Remove query strings from static content. (It will change from OFF to ON.)
  • Click Save Changes.

WP Performance Score Booster plugin for removing query strings from static resources

 

4. Speed Booster Pack

Say goodbye to high bounce rates with Speed Booster Pack. This plugin is all about strengthening your site’s usability for your visitors. 

  • Install and activate the plugin. 
  • Go to the Speed Booster tab on the left side of your dashboard. 
  • Under the General tab, click the slider next to Remove query strings. (It will change from white to blue.)
  • Click Save Changes.

Speed Booster Pack plugin for removing query strings from static resources

 

5. WP Remove Query Strings From Static Resources

This plugin is super easy for any novice WordPress user. You just install and activate it. There are no settings to configure on your admin dashboard. It starts immediately upon activation.

WP Remove Query Strings From Static Resources plugin

 

Testing the Removal of Your Query Strings from Static Resources 

Now it’s time to test your website load time again. Revisit the free website performance tools mentioned above and run another test. 

For example, here are the results of a test website with query strings using Pingdom. The website scored a 22 out of 100. 

Pingdom results showing query strings from static resources

Source: KeyCDN

After removing the query strings from static resources, the test website scored a 100 out of 100. The new results show no more URLs with query strings. 

Pingdom results showing removal of query strings from static resources

Source: KeyCDN

For your WordPress website, page speed is critical to getting high rankings on search engines and enhancing the visitor experience. A simple fix of removing the query strings from static resources is worth the effort to improve your website.

Use HubSpot tools on your WordPress website and connect the two platforms  without dealing with code. Click here to learn more.

Related Articles

Capture, organize, and engage web visitors with free forms, live chat, CRM, analytics, and more.

DOWNLOAD THE FREE PLUGIN

CMS Hub is flexible for marketers, powerful for developers, and gives customers a personalized, secure experience

START FREE OR GET A DEMO