Jump to content

How To Force A Browser To Clear Cache In Web Code


Recommended Posts

  • Administrators


While developing and making updates to a website you sometimes cannot see the changes in real-time.  Even if you’re not running any caching mechanisms the browser itself will still cache items such as CSS stylesheets and JavaScript/jQuery files.

Today we had a client that was using no caching plugins within WordPress or any caching tools on the server.  Yet after our upgrade of the WordPress core and several plugins the site would not show these updates unless we forced the desktop browser to hard dump the cache.  This really isn’t a viable option as users that may have already visited the website wouldn’t know how to do this and you wouldn’t expect them to.  Mobile devices seem to cache even longer so waiting on the normal cache expiration time just wasn’t an issue.

Short of looking through all plugins and how they load these files and then versioning them manually, which they should already be doing in our opinion, the next best option was to add some HTML meta data to the header of the website.

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

We tried all of the above, but it was still not working.  If you didn’t have this code in your header previously then chances are it’s already cached and it will not force the cache dump.  That when we stumbled upon Busted!.  It’s a WordPress plugin that forces your browser to dump it’s cache when enabled.

It hasn’t been updated in the past three years, but it still works with the most recent version of WordPress, tested on WordPress version 4.9.4.  Right after installing we checked some mobile devices such as iOS Safari and the site loaded showing the new changes.

Link to comment
Share on other sites

  • 8 months later...

Hell. I had been searching for this every place I knew. And I find this here on my very first day. Lucky Me!!!

Many of my clients have always this issue. Mostly been using those caching plugins and as such, almost every time you alter some CSS Styles, you definitely need to manually clear the server caches. And then, when you view, the browser cache does not clear up unless you do this manually. My problem - I always have at least 15 tabs on my browser where I am logged in and clearing the cache right now... well, it is a dreadful thought for sure.

I am thankful to you @Nathan for mentioning this "Busted". I am surely gonna implement it on most of my clients.

On 3/24/2018 at 11:21 AM, Nathan said:

It hasn’t been updated in the past three years, but it still works with the most recent version of WordPress, tested on WordPress version 4.9.4.

I know of a few plugins that havent been updated in years, but still work good with Wordpress. If this plugin - Busted - worked on 4.9.4 I do assume, it will work for years to come - as it works on PHP 7.x. Many wordpress installations now run on php 7.x and so I assume, your installation too was on version 7.x.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...