Rahil Rahil -4 years ago 200
AngularJS Question

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.

Answer Source

There Are Many Ways to do, I am going to provide one of those.

If you use manual reference then you can add update version on each release under you web config and also update string with version.

Add below to you code page

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

And You Also have to update Your web config file

<appSettings>
      <add key="Config.Version" value="2.0.9"/>
</appSettings>

Please check it with this and let me know if you face any issues. I am happy to help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download