I want disable caching on my static website. Currently I'm using the myFile.js?v=123
trick, and update the number every time I make a change. But I'm sure there's a better way of doing this.
This question is not a duplicate of How do we control web page caching, across all browsers? . The accepted answer there was helpful to me, however, it only offers one way of setting the HTTP header that is possible on a static website (I think), and that is using these 3 HTML meta tags:
<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" />
Unfortunately, the answer also explains that these tags do not take precedence and therefore usually don't work.
Is there any reliable way of disabling cache on a static website, or is what I'm asking for impossible? Thanks for your help!
I want disable caching on my static website. Currently I'm using the myFile.js?v=123
trick, and update the number every time I make a change. But I'm sure there's a better way of doing this.
This question is not a duplicate of How do we control web page caching, across all browsers? . The accepted answer there was helpful to me, however, it only offers one way of setting the HTTP header that is possible on a static website (I think), and that is using these 3 HTML meta tags:
<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" />
Unfortunately, the answer also explains that these tags do not take precedence and therefore usually don't work.
Is there any reliable way of disabling cache on a static website, or is what I'm asking for impossible? Thanks for your help!
Share Improve this question asked 15 hours ago Petra1999Petra1999 651 silver badge14 bronze badges 1 |1 Answer
Reset to default 0meta tags like Cache-Control aren't guaranteed to work because they don't always take precedence over HTTP headers. Meta tags not often have much effect on caching behavior in some browsers, or they might be overridden by other settings
Best solution is to configure HTTP headers. Make .htaccess file on server and put this code in it
<FilesMatch "\.(html|js|css|jpg|jpeg|png|gif|svg|webp)$">
Header set Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate"
</FilesMatch>
Other solution is to use service worker
myFile.js?v=123
is the most effective way to ensure that files are not cached on a static website. – MHD Alaa Alhaj Commented 15 hours ago