Blog > WordPress WordPress Tutorials > How to Remove Query Strings from Static Resources in WordPress?

How to Remove Query Strings from Static Resources in WordPress?

You might have heard that an average user waits less than 15 seconds on a website to load completely before going away.

That means if you are running a website that takes ages to load, your visitors will go away even before the site loads completely.

Do you know what that equates to? You will lose a lot of visitors and therefore, you will be leaving a lot of money on the table.

Speed is a pivotal part of your site, and it plays a significant role in either keeping or scaring away your visitors.

If you are serious to have readers who pay recurring visits to your site or you want to make more money from your products and services, never neglect any issue related to the speed of your website.

Your site is going to record a high bounce rate if your visitors keep leaving because it loads too slowly. In that case, people who might be interested in doing business with you might look for other ways – for a site with better loading speed.

This means, less conversion rates for your business.

After knowing how vital the site’s loading speed is, the next question that you may want to ask is what is responsible for a site loading slowly? Well, there are several reasons why this may happen.

In this post, we will pay attention to the issue of Query String, which is one of the culprits.

 

What is a Query String?

A query string is a URL containing either “&” or “?” at the end of your site’s URL. It consists of a group of keywords which a web browser adds to the base URL. A query string is created when a user keys in variables for the search of a database.

The search engine will generate a dynamic URL, including the query string, based on the results. The “?” is actually not a part of the query string, but operates as a separator.

Why should you remove Query Strings?

In 2010, Google added website speed to its SEO ranking algorithm. You can quickly increase website speed by caching static resources such as CSS and JavaScript by making use of CDNs and proxies.

Nevertheless, the presence of query strings makes it impossible to cache a resource. It increases a page’s loading time, though it allows any update to reflect instantaneously. It is, therefore, wise to get rid of these query strings to give room for caching and improve your website’s speed.

Apart from helping to test website speed, some tools like GTmetrix, Pingdom, Page Speed tools or WebPagetest, recommend improving the speed of your website, among the other things. One of the things they mostly advise for webmasters is to remove query strings from static resources.

Because of the excessive length of query strings, they do not play a part in the hierarchical path structure. They are hardly useful in sending a load of information. Apart from that, they pose a security threat because the data is directly visible to the user.

Various ways of removing Query Strings

In reality, there are two basic ways to remove query strings from static resources. They include adding a small piece of code in your functions.php file or via the use of plugins.

So, without much ado, let’s get down to business and show you the various plugins and the code to use.

1 Remove Query Strings from Static Resources with Code

You can easily remove query strings from your assets with a few lines of code. Add the following piece of code to your WordPress theme’s functions.php file.

function remove_query_strings() {

if(!is_admin()) {

add_filter('script_loader_src', 'remove_query_strings_split', 15);

add_filter('style_loader_src', 'remove_query_strings_split', 15);

}

}

function remove_query_strings_split($src){

$output = preg_split("/(&ver|\?ver)/", $src);

return $output[0];

}

add_action('init', 'remove_query_strings');

Note: You should edit the source code of a WordPress theme carefully in order to not break your site. If you do not know precisely how to handle the situation, consult a developer to help you out.

Alternatively, you should make use of the free Code Snippets plugin. It enables you to add codes to your site without unnecessarily breaking your site.

2 Plugins to Remove Query Strings from Static Resources

1. W3 Total Cache

How-to-Remove-Query-Strings–from-Static-Resources-in-WordPress-with-W3-Total-Cache

W3 Total Cache has over a million downloads, making it one of the most popular plugins for WordPress users. It can work on any environment since it was not explicitly designed for any particular hosting service.

It comes with multiple functions, amongst which is the removal of query strings. In a nutshell, the plugin is designed to improve the overall performance of the website.

W3 Total Cache is one of the top choices of webmasters for caching static resources.

The simple way to do it is to add some changes in the settings which help to stop the creation of query strings. Under the settings, click on ‘Browser Cache’ and uncheck the box ‘Prevent caching of objects after settings change.’

2. Query Monitor

How-to-Remove-Query-Strings-from-Static-Resources-in-WordPress

Query Monitor is a free WordPress plugin that helps you to optimize your website. The tool is user-friendly and easy to set up. It makes things easier by displaying easy to understand reports.

With this, you can scan reports seamlessly and act in accordance. Its primary functions include monitoring database queries, HTTP API calls, PHP errors, and lots more. It also gives you insight into themes and plugins that are not performing well.

Upon activation, the Query Monitor adds an admin toolbar to the menu to enable you to examine the current page more. It provides notifications of duplicate, slow, error queries to allow you to make the necessary corrections. You can also set in the settings panel to whom Query Monitor shows its stats.

3. Remove Query Strings from Static Resources

Remove-Query-Strings-from-Static-Resources-WordPress-plugin

Remove Query Strings from Static Resources is a free plugin that is renowned for its ability to clean out query strings from JavaScript and CSS files within the HTML. Your site gets noticeable improvements in speed scores after the plugin has cleaned it up.

Installing and using the plugin is easy. A lot of users have noticed an increase in their site’s speed after installing the plugin. Once you install and activate the plugin, you are good to go. It does not require any other special attention to do its job.

Note that the plugin only removes the query strings from the HTML <head> element, and other query strings in the body are untouched.

4. WP Speed of Light

WP-Speed-Of-Light-WordPress-plugin

Just as the name implies, the WP Speed of Light plugin makes your website load with the speed of light, thereby giving your visitors a wonderful experience. This plugin ensures that your WordPress site does not slow down unnecessarily as a result of extra features and functions.

It offers optimization, compression, cleaning, and caching of your website to make it function more efficiently. With the optimization, mobile users have a better experience as they are presented with a faster loading website.

5. Comet Cache

Comet-Cache-WordPress-pugin

Comet Cache builds a cache of each page, post, and link available on your site and gives them some intuitive touch. These cached pages become relatively faster to load.

Comet Cache displays an item in the dashboard menu, thereby giving you access to configure it to suit your desire.

Besides enabling caching, it gives you the liberty to set up an automatic expiration time for cache files. The pro version is available in case you want to make use of a CDN, auto-cache engine, HTML compression, automatic updater and lot more.

6. Speed Booster Pack

Speed Booster Pack is a multipurpose plugin which can increase the speed of your site. It is user-friendly and only bends you to install and activate it to function.

After activation, a new sub-menu item ‘Speed Booster Pack’ becomes visible on your dashboard, giving you access to adjust the preferences.

The plugin equally displays brief statistics related to your homepage loading speed in the options page. It also shows the number of queries it has processed in the progress color bar.

The plugin facilitates lazy loading of images and loads CSS in a self-paced manner apart from removing query strings. Speed Booster Pack loads JavaScript files from Google libraries, minifies JavaScript and HTML and moves scripts to the footer. Options are available for you to configure the plugin to improve your site’s speed.

Conclusion

Query Strings hinders page caching and as a result, it increases the loading time of the page. Hence your site loads slower than expected. Therefore, query strings have to be removed.

We have shared two main ways to get rid of the Query strings – by using a code or by using a WordPress plugin.

For the sake of clarity, let us quickly run over the list of the plugins to use for this purpose – W3 Total Cache, Query Monitor, Remove Query Strings from Static Resources, WP Speed of Light, Comet Cache, and Speed Booster Pack.

However, these are not the only plugins that one can use for removing query strings. Nevertheless, we decided to talk about the six of them because we have tested and found that they are highly useful and could help to improve the speed of your site.

Note: It is not necessary to use all of them at the same time on your site. You need to test each of them to see which best suits your site in improving its loading time.

Leave a reply

x