Website needs force refresh after deploy

46,654

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

Share:
46,654
Stefano
Author by

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, 2020

Comments

  • Stefano
    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
    Stefano almost 13 years
    Isn't there an easier way to do this? I am loading 1000s of resources
  • ceejayoz
    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
    ceejayoz almost 13 years
    That can be bad performance-wise, though. Caching saves users a lot of bandwidth and time.
  • stefgosselin
    stefgosselin almost 13 years
    You 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
    stefgosselin almost 13 years
    Basically, you would need 2 headers: Cache-Control: must-revalidate and Last-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
    m.edmondson almost 13 years
    @ceejayoz - Thanks I didn't think of doing it that way
  • NorCalKnockOut
    NorCalKnockOut about 8 years
    @ceejayoz Old question, but what if the config file gets cached?
  • ceejayoz
    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
    NorCalKnockOut about 8 years
    @ceejayoz Ahh duh. Thanks!
  • Asad
    Asad over 7 years
    @ceejayoz can you, please explain how can I use a variable from the config file in my .aspx page?
  • ceejayoz
    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
    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
    Jolley71717 about 6 years
    This 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?