简体   繁体   中英

How to force a browser to clear the cache on my website .html files

I've recently made changes to a clients website but the browser is showing a cached version. It's a static website with .html files. If I delete the cache on my browser it works but what i really want is to force every visitors browser to show the latest version without them having to manually delete their cache.

I understand that you can set a version on .css & .js file to show the latest version but how do you do this with static .html files?

If this is about .css and .js changes, one way is to to "cache busting" is by appending something like "_versionNo" to the file name for each release. For example:

script_1.0.css // This is the URL for release 1.0
script_1.1.css // This is the URL for release 1.1
script_1.2.css // etc.

Or alternatively do it after the file name:

script.css?v=1.0 // This is the URL for release 1.0
script.css?v=1.1 // This is the URL for release 1.1
script.css?v=1.2 // etc.

And you can have a look at here too META TAGS

I think better you don't need to cache html file

<ifModule mod_headers.c>
<FilesMatch "\.(html|htm|txt)$">
  Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
</FilesMatch>
</ifModule>

Save it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM