简体   繁体   中英

Load already live HTML file from server instead of browser cache

I have a live website, but as changes are always there, I need the user to view the latest HTML files, ie load the files from the server instead of browser cache.

When this website went live I didn't know about:

<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">

I have made my website using HTML, CSS, jQuery and PHP where necessary.

What can I do to make the website load directly from the server?

I updated the HTML code with the meta tags, but since I already have the page in my cache, the new HTML code (with meta tags) is not running. I can simply hard refresh and work, but the users won't know or do that.

If you need to force everyone's browser to reload a plain .html page you could add the 'Cache-Control` header to your webservers configuration:

Nginx

location ~* \.(html)$ {
 add_header Cache-Control "no-cache, no-store";
}

Apache

<filesMatch ".(html)$">
    Header set Cache-Control "no-cache, no-store"
</filesMatch>

If the change however is in a file that your .html page is loading, such as a .js .css you can use this 'cache busting' technique:

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.

This will force the browser to load the new file.

<meta http-equiv=“Pragma” content=”no-cache”><meta http-equiv=“Expires” content=”-1″><meta http-equiv=“CACHE-CONTROL” content=”NO-CACHE”>

Try this . But When you force a site to load from the server instead of the cache, you affect performance. Therefore, before you add these meta tags to your site, ask yourself if this is truly necessary and worth the performance hit that the site will take as a result.

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