Force update on client side after site update

9

The scenario for my problem is the following, I have a website that has been updated, but some customers are reporting that the update was not made for them, which are still in the old site template (probably due to cache persistence ).

I've made several updates and never had this problem. I do not know if it was the size of the update (basically a rework of the whole project) that is implying this problem, but I can not get users to access the new version of the site.

I know that cleaning the cache , ctrl + f5 , ctrl + r may help, but, unfeasible ...

I already use version practice in files, for example:

scr="meuscript.js?v=0123456"

href="meuestilo.css?v=0123456"

I also use some tags in HTML, like:

<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

But nothing had the desired effect. I confess that it is an area that I do not have much experience and knowledge. So, what could I do to get the desired result? That is, force page refresh (or cache ) on the client side?

    
asked by anonymous 23.03.2017 / 20:28

3 answers

4

Something I've seen in this SOEng response

Picking up the part that really matters:

When these values are provided through the headers of the request responses, they take precedence over the <meta> tags. some servers send default values, so it is advisable to explicitly send headers to the response.

You can check what's coming with DevTools by going to the Network > clicking on the request of your page > check the header Cache-Control in the Response Headers section of the Headers sidebar.

Using PHP:

header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.

Using Java Servlet , or Node.js:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setHeader("Expires", "0"); // Proxies.

Using ASP.NET-MVC

Response.Cache.SetCacheability(HttpCacheability.NoCache);  // HTTP 1.1.
Response.Cache.AppendCacheExtension("no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

Using ASP.NET:

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

Using ASP:

Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate" ' HTTP 1.1.
Response.addHeader "Pragma", "no-cache" ' HTTP 1.0.
Response.addHeader "Expires", "0" ' Proxies.
    
23.03.2017 / 21:21
0

Friend, a very simple solution is to rename the HTML / CSS / JS files that have been modified (and of course, change where they are also called), so the browser does not recognize anything in cache and loads fresh files. p>     

03.08.2018 / 06:59
-1

One method to force the browser to clear the cache is the HTML5 cache app. You create a Manifest file where you write what should be cached and what should not be cached.

ALWAYS that the manifest file is updated, the resources will be mandatory UPDATED . (be sure to clear the amount of meta tag you used on the cache) an example of a manifest:

CACHE MANIFEST
# 2012-02-21 v1.0.0
/theme.css #em cache
/logo.gif # em cache
/main.js # em cache

NETWORK:
login.asp #nunca será mantido em cache

FALLBACK:
/html/ /offline.html

Take a look if it helps:

link

    
24.03.2017 / 17:43