Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  161] [ 7]  / answers: 1 / hits: 19857  / 7 Years ago, fri, march 17, 2017, 12:00:00

Many people use version numbers on css and js files to force non-cached versions to load up on webpages when updates are published:



CSS example:



<link rel=stylesheet type=text/css href=style.css?v=2017-03-17>


JS example:



<script type=text/javascript src=js/myscript.js?v=2017-03-17></script>


I've noticed that by adding version numbers to css/js files, the web browsers will also load up the HTML file (from which the css/js files are referenced from) from scratch and not use the cached version.



Is this a sufficient way of ensuring that HTML-files are displayed from scratch in all web browsers, or is there a way to set a version number to the HTML file as well, to ensure newly updated HTML-documents are not loaded from a browser's cache?


More From » html

 Answers
8

Usually the browser takes always the newer version of your HTML.



If you wish to prevent any cache you can use those tricks:




The correct minimum set of headers that works across the most
important browsers:



Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0


HTML



<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 />


.htaccess (Apache)



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


Java Servlet



response.setHeader(Cache-Control, no-cache, no-store, must-revalidate);
response.setHeader(Pragma, no-cache);
response.setDateHeader(Expires, 0);


PHP



header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');


ASP



Response.addHeader Cache-Control, no-cache, no-store, must-revalidate
Response.addHeader Pragma, no-cache
Response.addHeader Expires, 0


ASP.NET



Response.AppendHeader(Cache-Control, no-cache, no-store, must-revalidate);
Response.AppendHeader(Pragma, no-cache);
Response.AppendHeader(Expires, 0);


Ruby on Rails



response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '0'


Python on Flask



resp.headers[Cache-Control] = no-cache, no-store, must-revalidate
resp.headers[Pragma] = no-cache
resp.headers[Expires] = 0


Google Go



responseWriter.Header().Set(Cache-Control, no-cache, no-store, must-revalidate)
responseWriter.Header().Set(Pragma, no-cache)
responseWriter.Header().Set(Expires, 0)



source: http://cristian.sulea.net/blog.php?p=2014-01-14-disable-browser-caching-with-meta-html-tags


[#58508] Wednesday, March 15, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micah

Total Points: 295
Total Questions: 104
Total Answers: 92

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;