1

I'm trying to figure out how the easiest way would be to force endusers browser to clear cache.

We are working in visual studio with .Net WebForms and AngularJs

So every time we deploy our .Net project to test or production enviroment we got problems with cache saving old javascript and hides new implementation...

I know a couple solutions but I wanna see if there are any other?

Thanks in advance!

2
  • 1
    What are your couple of solutions? Commented Aug 18, 2014 at 8:21
  • Why downvote? One solution would be to use datestamp in javascriptfiles or use <add key=1.5.4... in web.config.. shortly explained. Commented Aug 18, 2014 at 8:26

2 Answers 2

3

Right click in this page and select view source, you will see static files suffixed as follows:

<script src="//cdn.sstatic.net/Js/stub.en.js?v=b1fcfe635df7"></script>

Basically this is kind of the best method, generate some suffix and append that to the end of all of your static files as a querystring parameter. That will force the browser into thinking that the file is new, i.e. if the querystring has changed...

The rub here though is how often do you change those files... how often do you want to force the user to download new static files... using a generated timestamp could force the user to download the file everytime they visit the site, often not ideal.... Maybe use the web.config date or something like it.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep! Going for this! In Web.Config: <add key="version" value="1.6.1.2"/> Then on javascriptfiles ending: ?v=<%=ConfigurationManager.AppSettings("version")%
Yes that will work nicely, the point I made about using something like the web.config last modified date is that it is 'automatic', i.e. you will not have to manually alter the key in the web.config. Although doing it manually you could bypass issuing a build if you only uploaded a new style sheet kind of thing... pros and cons, whichever works best.
1

you can add below settings in web.config to disable caching

  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="DisableCache" />
    </staticContent>
  </system.webServer>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.