0

I have a very simple HTML/CSS/JS website. When ever I make changes to it, to see the updated version I have to manually clear my cache on mobile or hard reload on PC.

Is there a way of clearing cache for your site on users browsers? I have had a look around but I seem to only find of instances of clearing server cache and libraries that I don't know have to use yet. Many thanks in advance for your help!

1 Answers1

0

Browsers will cache:

  • the html files
  • the JS files
  • the CSS files

It's probably best to do this on the server side, but you can first try doing it on the client side as described below.

To make sure the latest html file is used, you could try adding this within the <head> of your html files:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>

To make sure the latest version of "mycode.js" is used, append a new value to the file (e.g. the timestamp it was last edited):

<script src="mycode.js?v=123456789"></script>

Same thing to make sure the latest "mystyle.css" file is used:

<link rel="stylesheet" type="text/css" href="mystyle.css?v=123456789">
Alan P.
  • 2,898
  • 6
  • 28
  • 52