Website needs force refresh after deploy
Solution 1
You can append a variable to the end of each of your resources that changes with each deploy. For example you can name your stylesheets:
styles.css?id=1
with the id changing each time.
This will force the browser to download the new version as it cannot find it in its cache.
Solution 2
For ASP.NET you can use the cache control and expires headers. You can also set up similar headers in IIS 7 for your images. If you have any other cookies you can expire them manually.
I have not tried it, but it looks like you can do an ever better job of bulk setting cache control in IIS 7. See this thread and this link. At that point you are only left with unsetting any custom cookies you have (which you won't be able to control with HTTP cache control settings).
I don't know of any method to "unset everything all at once" easily.
Solution 3
You could use http headers to control the cache of your clients.
I'll just leave this here for you. http://support.microsoft.com/kb/234067
Stefano
I'm a software developer. I like web comics, TV-shows, movies, PC games and books. Read my blog if you want to find out more about me.
Updated on June 08, 2020Comments
-
Stefano almost 4 years
After deploying a new version of a website the browser loads everything from its cache from the old webpage until a force refresh is done. Images are old, cookies are old, and some AJAX parts are not working.
How should I proceed to serve the users with the latest version of the page after deploy?
The webpage is an ASP.Net webpage using IIS7+.
-
Stefano almost 13 yearsIsn't there an easier way to do this? I am loading 1000s of resources
-
ceejayoz almost 13 years@Germstorm Set a variable in a config file and update it. Add that variable to all resource calls. One update, every URL changes.
-
ceejayoz almost 13 yearsThat can be bad performance-wise, though. Caching saves users a lot of bandwidth and time.
-
stefgosselin almost 13 yearsYou can (and should) control the cache header, via LAST-MODIFIED directive, or ETags, See this page for quick run-down, and this one for more in depth explanations
-
stefgosselin almost 13 yearsBasically, you would need 2 headers:
Cache-Control: must-revalidate
andLast-Modified: 15 May 2011 17:43:00 GMT
this is the only way I know of to have control of client caching mecanisms. -
m.edmondson almost 13 years@ceejayoz - Thanks I didn't think of doing it that way
-
NorCalKnockOut about 8 years@ceejayoz Old question, but what if the config file gets cached?
-
ceejayoz about 8 years@NorCalKnockOut The config file would be server-side. If there's caching on it, that's controlled by you and/or your server, not the client.
-
NorCalKnockOut about 8 years@ceejayoz Ahh duh. Thanks!
-
Asad over 7 years@ceejayoz can you, please explain how can I use a variable from the config file in my .aspx page?
-
ceejayoz over 7 years@Asad No clue. In PHP it'd just be something like
styles.css?id=<?php echo $version; ?>
but I have no idea what similar ASP syntax would be. -
Asad over 7 years@ceejayoz Thanks,this is how I managed this in my .aspx page.
<%string versionNo = "2.4.1.9999"; %>
<link href="css/spectrum.css?id=<%=versionNo %>" rel="stylesheet" />
-
Jolley71717 about 6 yearsThis may seem like a strange question, but if you add the variable to the config file and call that variable in your resource call on the page, what happens when the page gets cached? Since the config file is on the server, the cached web page will call the new config value and get the correct resource, but the page is still cached, right?