Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop caching while using angularjs

I used AngularJS v1.5.7 with .net MVC WEB project, and my content is with in index.cshtml with ui-view.

For an reason, I found all of my html/js files are cached in chrome or any browser.

The changes i use to make to html/Js files are not getting reflected to browser until unless i clear browser cache manually. I am unable to see any changes that i made even after pressing F5 or ctrl+F5 ,

I am supposed to manually clear the browsing cache.

How do I prevent client to clear their browser cache when new versions are deployed on server.

How do I clear cache by programming when I deploy new version of my site.

like image 715
Rahil Avatar asked Sep 11 '26 05:09

Rahil


1 Answers

There are various way to do so.

  1. First of all you can use bundling & magnification so it will automatically load new bundle on each release.
  2. If you have used manual reference then you can add query string with version. And can update version on each release under you web config.
<appSettings>
      <add key="Config.Version" value="2.0.9"/>
</appSettings>

under you page

<script src="@Url.Content("~/scripts/case/addcase.js?v=" + Config.Version)" type="text/javascript"></script>

Also if it is something related to angular, You can try

https://github.com/saintmac/angular-cache-buster

as suggeted by @Sajan Mullappally in comment

like image 138
Kaushik Thanki Avatar answered Sep 13 '26 17:09

Kaushik Thanki