Update the html file so that the browser does not use it in the cache

I thought I had a problem with javascript caching and did not update even with the tag of the updated version, for example:

<script type="text/javascript" src="lib/myScript.min.js?v=3"></script> 

But I realized that the problem is that my html file is cached ... so the browser does not even know that there is a new script file.

I don’t want to disable caching, but is there really no way to tell the browser that it doesn’t have the most modern html file? (And this is what I put in my html file or on my apache2 server?)

+4
source share
3 answers
 <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" /> 

Answer from Using tags to disable caching in all browsers?

+4
source

You can try these meta tags. I think this will solve your problem.

 <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> 
+2
source

Besides writing explicitly in html, you actually have two best options: ETAG and Last-Modified . If your html file is a static file, then apache2 will know how to handle its cache by default. if it is php then you will have to process it in your code or use some frame structure.

Since these two headers are not written in html, the browser does not need to download the entire text of the HTTP response and thereby reduce traffic. Therefore, I suggest you use them.

I believe a small search engine can help.

Which has the advantage: ETag header or Last-Modified HTTP?

+1
source

Source: https://habr.com/ru/post/1432456/


All Articles