3

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.

4
  • 2
    append version number to your js files after each publish, like landing.js?v1 - for version1 then for next version landing.js?v2 and so on for each next publish. Commented Feb 8, 2017 at 7:10
  • Hello I am using Ionic with Angular and using <ion-view cache-view="false"> prevents caching not sure if that works for you too Commented Feb 8, 2017 at 11:42
  • No man this want work, Ionic do itself provide this facility ,but not for my web project-- well anyhow thanks @stackg91 Commented Feb 8, 2017 at 13:19
  • 1
    try using github.com/saintmac/angular-cache-buster. It automatically adds timestamp after filename. You can use it for development to solve the caching issue and remove it on production Commented Feb 9, 2017 at 4:52

2 Answers 2

3

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

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

Comments

0

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.

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.