1

I just want to clear the browser cache using angularjs, every time i login to my application and browser should load new files.

3
  • 2
    through javascript? Commented Nov 22, 2016 at 13:22
  • 2
    maybe have a look at a previous post stackoverflow.com/questions/31850824/… Commented Nov 22, 2016 at 13:22
  • javascript or angularjs whatever the best way. Commented Nov 22, 2016 at 13:24

2 Answers 2

8

You don't really do this using Angular, per se. There are a few ways you can cause your browser cache to invalidate/force your browser to request a fresh resource. A common way of doing this is cache busting your application assets. For example, whenever your JS changes, you have a task running (Grunt/Gulp/Webpack are good examples of this) that will rename your file to something new (usually by appending a hash or date to the end of the filename) so that when your browser requests your page, it will see a brand new filename and request a copy of it.

An example of something that can do this is gulp-rev: https://github.com/sindresorhus/gulp-rev and here is a tutorial: https://stefanimhoff.de/2014/gulp-tutorial-13-revisioning/

Hopefully this helps!

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

1 Comment

That';s the good solution. Don't forget to force refresh index.html using a meta tag and everything will work like a charm: stackoverflow.com/questions/1341089/…
1

I recommand you to use grunt-cache-breaker is a simple cache-breaker, appends a timestamp or md5 hash to any url.

This plugin requires Grunt.

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.