Remove Query Strings from Static Resources to Increase your Website Speed

0
365
Remove Query Strings from Static Resources to Increase your Website Speed

JavaScript is a language. We sometimes need to remove text from string to get desired output from certain API calls or from a JavaScript APP.

Removing text using String.prototype

Remove Query Strings from Static Resources to Increase your Website SpeedBy this method it does not change the original string but returns a new string.

Removing text in JavaScript using slice() method

This method extracts parts of a string and returns the extracted parts as a new string. It takes two parameter which specify the parts of the string to be extracted.

Start:

it specifies the position to begin the extraction. This parameter is mandatory. The first character is at position 0.

End:

it specifies the position where the extraction should end. This parameter is optional and if not provided, slice() selects all characters from the start position to the end of the string.

JavaScript code to remove text from String and extract only number

remove query strings from static resources wordpressFor this we have to use regular expression and match that to the given string and get the output as number.

Remove Query Strings from Static Resources to Increase your Website Speed

Page load time is an essential aspect for a website or blog. It helps to deliver an effective user experience to visitors. It also helps to get higher ranking in google search as a result will increase in overall traffic on your website.

What are the Query Strings in WordPress?

remove query strings wordpressQuery strings are the URLs which contains “?” or “&”. It is similar to CSS and JS files to website, which is usually have the file version on the end of their URLs. Therefore query strings resources would be resource URLs with a “?” or “&”.

Most of the proxy servers do not cache CSS and JavaScript resources with Query strings, even if have optimized Public Cache-Control headers.

The Query Strings are used to version a file which differentiates the resource files from one to another. It useful for developers to avoid caching problems.

Should you Remove Query Strings from Static Resources?

remove query strings from static resources htaccessQuery Strings prevent caching of static resources like CSS and JavaScript on proxy servers and CDNs, which results in slow loading speed of a website. Once the strings are removed, the speed of the page increases.

How to Remove Query Strings from Static Resources?

To remove query strings from your site resources, you need to add filter hook in the functions.php file to modify static resources URLs i.e. CSS and JavaScript. Filter hooks are used to modify various types of internal data in WordPress.

The step by step process to remove Query Strings from Static Resources like CSS and JavaScript is as follows:

  1. Open the functions.php file of your WordPress theme
  2. Copy and paste the given-below code at the end of functions.php file.

Remove Query Strings from Static Resources – WordPress plugin

1. Remove Query Strings from Static Resources – WP plugin

remove query strings from static resources wordpress pluginQuery Strings can be removed by using a WordPress plugin called remove query strings from static resources. By installing and activating this plugin, there will be no setting panel.

2. W3 Total Cache – WP plugin

remove query strings from static resources w3 total cacheRemove Query Strings from Static Resources with W3 Total Cache plugin. Users can use W3 Total Cache plugin settings optimization guide to increase web page loading time. This plugin will increase the website loading speed.

W3 total cache plugin offers an option to remove query strings resources. It is only needed to UNCHECK an option and it will remove query strings from 90% of 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’. Now ‘empty all cache’. The speed of the page will increase.

3. WP Remove Query Strings from Static Resources

remove query strings from static resources wordpressAll the Query Strings will be removed automatically from static resources by installing the plugin and activate it.

MINIFY JAVASCRIPT IN WORDPRESS

Why minifying is so important?

how to minify javascript and css in wordpress without pluginMinification reduces reduces size of web page which result to increase in PageSpeed.

What is minifying?

Minifying process removes any unwanted code from website like

  • Unused spaces that is written CSS
  • Unnecessary line-breaks in HTML
  • Unnecessary code written in JavaScript

Minify JavaScript and CSS in WordPress

minify javascript and css in wordpressMinify JavaScript and CSS in WordPress – with plugin

It will update theme on regular basis . Any theme update will not hamper file magnification process.

4. W3 Total Cache

remove query strings from static resources w3 total cacheMany of the WordPress users use this plugin to increase web PageSpeed.

  • Install W3 total cache plugin and activate it.
  • Go to the general settings tab and minify settings
  • Check minify enable setting
  • Click on save all settings button, clear all cache

5. Autoptimize

  • Install this plugin and activate it
  • Go to plugin’s setting panel
  • Check optimize HTML code, Optimize JavaScript code, optimize CSS code, generate data, URLs for images
  • Click on save changes and empty cache button.

6. WP Fastest Cache

remove query strings from static resources WP fastest cacheThis plugin is also used for leverage browser caching. This plugin offer to minify JavaScript, CSS and HTML files along with browser caching.

7. Fast Velocity Minify

remove query strings from static resources fastest velocity cacheFast Velocity Minify is a good plugin for pagespeed optimization.this plufin offers good feature like Gzip. Compression, option to defer JavaScript and CSS files can filter specified scripts and CSS files.

 

Explosionweb Solutions is a multifaceted young organization. We specialize in creating top-notch web solutions for your business. We are a team of dedicated and creative professionals continuously working towards making your business realize its true online potential. We have a bold and promising approach to digital marketing, branding, App development and many more online services.