Ads by Google

How to clear cache on a website without any plugin

At our work we often come across to a problem with caching data in browsers. If we build an application that uses a large number of people, we quickly realize that there is a huge number of devices and browsers that visit our web site. If we make a small change in a design or in scripts (HTML, CSS or JavaScript), we will have a problem with displaying these pages – because the old cache will remain the same in a browser for some time (and that can make many problems). Therefore, we need to use a few “tricks” to clear the cache globally.

Here is the guide on how to clear cache on a website without any plugin.

CSS and JavaScript

when it comes to CSS and JavaScript, it is great to add “versions” of your files. Example:

If you follow this advice, when you change your file name you will force a browser to load the new data. If you think that’s not a good idea and you don’t want to change your file name, here is a better solution:

You can add GET values, manually or dynamically, on what will browser read like a full URL.  with ?v=1.x you can use the same file name with unlimited number of versions.

The same is with JavaScript (JS) files:

Clear cache in WordPress without any plugin

In WordPress you have an option for versions of included JS files in wp_enqueue_script() in PHP:

Here is the great DOCUMENTATION on how to use this function.

You can also do similar things in WordPress for CSS but manually in URL:

When you change something in your CSS or JS, just change a version of your file and cache will be deleted.

Clear cache of <img> tags and background images in HTML

To clear cache of these images follow the same trick as with CSS or JavaScript:

As you see, it’s pretty easy. Using PHP and a random function for each image you can clear cache on each visited page:

Clear cache in input forms and autocomplete

Text and other input forms are not stored in the cache, but browsers collect that data and use auto-complete cache and auto-complete forms. These can be prevented with:

NOTE: autocomplete is supported only on a few browsers and works with the following <input> types: text, search, url, tel, email, password, datepickers, range, and color .

I hope this will be helpful. If you like our tutorials, please follow us and visit our website.

Summary
How to clear cache on a website without any plugin
Article Name
How to clear cache on a website without any plugin
Description
Here is the guide on how to clear cache on a website without any plugin.
Author
www.CreativForm.com