Force Update browser cache

Hey there!
I’ve updated my site recently and I am worried about the old version being cached in the browsers of users.
What can I do to make them load the new version? :sunny:

HI
It is best that you do not do anything about it because cache is there for a reason

how long a browser will be keeping some element in the cache depends on
how it’s defined in Cache-Control for the HTTP headers

if you talking about CSS or JS
you can add something like ?v=1.x to css file link, when the file content is changed.
for example if there was

<link rel="stylesheet" type="text/css" href="style.css">

you can change it to

<link rel="stylesheet" type="text/css" href="style.css?v=1.1">

and bypass caching


This should disable the cache on everything
put this in .htaccess file inside of your htdocs

 # no cache 
 <IfModule mod_headers.c>
 Header set Cache-Control "no-cache, no-store, must-revalidate"
 Header set Expires 0
 </IfModule>




NOTE that http/s requests to your website will grow rapidly

1 Like

Hi, @Oxy
Thanks a lot for your tips. I will try them immediately.

I am planning to use the code for .htaccess you provided for a bit, as a number of my users are just 5 or so. So I will just wait for them all to visit and recache the page. After that I will remove the code, so my hits should be fine. :smile:

1 Like

The idea suggested by @Oxy is good, but he is also right to suggest that disabling cache completely is typically not a good idea (not just because of the hits limit, it also makes your website slower)…

… but this won’t work without proper planning. When people first load a page, the content is downloaded and stored according to the cache headers sent at that time. So you would have to set the cache busting rules a day or so before making any changes, make then change and then remove the .htaccess rules.

1 Like

Oh gosh… I see what you are saying.

So how do people generally go about changing the contents of their sites? How would you do it? :flushed:

I’ve only got html and css stuff. Nothing super complicated.

Our main website is cached very aggressively, and so are the assets on this forum and the client area.

When we make changes, we just make sure to test them properly beforehand so we don’t accidentally upload broken code. When the code is uploaded, we don’t do anything with the cache. Yes, it will take a while for people to see the changes, but I’d say website performance is more important than seeing quick changes.

There is still one alternative strategy which you could try. Caching is typically based on the URL being requested. So, to circumvent the cache, you could upload the updated content with a new URL. So rather than updating styles.css, you could upload it as styles-201901261213.css and link to that stylesheet from your HTML code. Because the new file has a different URL, browsers will look for the new file (while still getting all the caching benefits).

1 Like

@Admin
Thank you!

I think that now it’s clear to me that changes will be shown after some time and there is no need to worry about cache too much. I will then just upload the changes and wait :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.