0

I am using VS 2013,Durandal, WebApi for my single page application. Whenever I deploy my code to server I have remove cache in browser to get the latest changes.

How could we avoid it? Let me know what more info is needed.

Also when I am in debugging code and if I do some changes in javascript file, then I have to remove cache to get latest changes.

James
  • 1,637
  • 4
  • 35
  • 56
  • Did you do any Google searches already on preventing content from being cached in the browser? If so, did you try any of the approaches that came up? – Frank van Puffelen Aug 18 '14 at 19:32
  • @FrankvanPuffelen i read about adding some random no to javascript file name but didnt found it somehow good – James Aug 18 '14 at 19:44
  • Have a look at this question's top answer: http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers?rq=1 . Specific to .NET's WebAPI: http://www.codeproject.com/Articles/682296/Setting-Cache-Control-HTTP-Headers-in-Web-API-Cont. Specific to Durandal: http://stackoverflow.com/questions/22720375/how-to-disable-cache-view-in-durandal – Frank van Puffelen Aug 18 '14 at 19:52
  • @FrankvanPuffelen I am using Durandal framework and none of answer fitted my question. Is there something i can add in web.config or something? – James Aug 18 '14 at 19:54
  • There are many things that affect caching and you're not providing us with any information to go on. I've given you a few links to look at. If those don't help, you'll have to provide more information about what you've already tried and what you're seeing in your browser (such as cache headers). – Frank van Puffelen Aug 18 '14 at 19:59
  • Durandal's recommended approach for development seems to indeed be to add a timestamp: http://durandaljs.com/documentation/Debugging.html#cache-busting. If you disagree with their approach, you can roll your own with the first link I gave you: they send the correct HTTP headers that tell the browser to not cache your files. – Frank van Puffelen Aug 18 '14 at 20:01
  • @FrankvanPuffelen how to use correct HTTP headers? In which part of file i have to make changes? – James Aug 18 '14 at 20:15
  • @Happy This is an exhaustive topic that has many varied opinions. You need to do further research and decide on which approach is best for you. In my experience, there is no single, best answer to this question. It depends. – Brett Aug 18 '14 at 23:16

1 Answers1

0

One thing you can look at is using require js url args, this is an option to add a cache busting query string to the end of all request made by require but as @FrankvanPuffelen stated, there are many places where caching happens so you have to really look at your app/server/clients. This setting can be set in the main.js file for your durnadal app.

Frank
  • 1,992
  • 1
  • 16
  • 22