Remove Query Strings From Static Resources In WordPress

Google uses page speed to rank any website on its search results page. Hence, removing query strings from static resources improves the performance of your website.

This not only betters your performance on SERPs but also enhances user experience, because no one wants to visit a website that takes lots of seconds to load.

Parameters affecting the speed of your website can be found using online tools such as Google Page Speed, Pingdom Tool and GTmetrix etc.

In this lesson you will learn about removing query strings from static resources which is a common factor affecting loading time of most websites on world wide web.

By Using A PHP Function

One solution is by adding this code in your theme’s function.php file or via Code Snippets plugin:

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

Implement this function on your website then check whether it is working good enough for your website or not.

By Using WordPress Plugins

There are various free WordPress plugins that enables you to remove query strings from static resources either by simple activation or by using a visual user interface.

Remove Query Strings From Static Resources

Another easy solution is using Remove Query Strings From Static Resources plugin in your WordPress website. The plugin is programmed to remove any query stings from static resources in your WordPress installation.

Start by installing it in your WordPress website. Upon activation, the query strings from static resources like CSS & JS files will be removed automatically. This will improve your speed scores in services like PageSpeed, YSlow, Pingdoom and GTmetrix.

remove-query-strings-from-static-resources

Likewise resources with a “?” or “&” in the URL are not cached by some proxy caching servers, and moving the query string and encode the parameters into the URL increases your website performance significant.

Query Strings Remover

Query Strings Remover is another plugin that gets this job done. It removes query strings from static resources like CSS & JS files. After activating this plugin make sure to empty your cached resources.

Speed Booster Pack

If you like having more options and features to improve page speed of your website, try Speed Booster Pack. The plugin is bundled with set of features:

  • Eliminates external render-blocking JavaScript and CSS in above-the-fold content.
  • Moves scripts to the footer to improve page loading speed.
  • Loads CSS asynchronously to make your page load more quickly and get a higher score on the major speed testing services.
  • Minify and inline all CSS styles and move them to the footer to eliminate external render-blocking CSS and optimize CSS delivery.
  • Lazy loads images to improve page load times and save bandwidth.
  • Changes image compression level to keep file sizes smaller.
  • Loads JavaScript files from Google Libraries rather than serving them from your WordPress install directly, to reduce latency, increase parallelism and improve caching.
  • Defers parsing of JavaScript files to reduce the initial load time of your page.
  • Removes query strings from static resources to improve your speed scores.
  • Removes extra Font Awesome stylesheets added to your theme by certain plugins, if Font Awesome is already used in your theme.
  • Removes junk header tags to clean up your WordPress Header.
  • Displays page loading time in the plugin options page.
  • Displays the number of executed queries in the plugin options page.
  • Displays the Peak Memory Used in the plugin options page.

Start by installing ‘Speed Booster Pack’ in your WordPress website. Upon activation, the plugin adds a new sub menu item in your main admin area ‘Settings’ menu.

Buit-in Option For W3 Total Cache Plugin Users

W3 Total Cache plugin users have a built-in option to remove query strings of static resources. All you got to do is visit your admin area dashboard ‘Browser cache’ settings page and remove tick from “Prevent caching of objects after settings change” checkbox option.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.