I just want to clear the browser cache using angularjs, every time i login to my application and browser should load new files.
-
2through javascript? – Sajeetharan Nov 22 '16 at 13:22
-
2maybe have a look at a previous post http://stackoverflow.com/questions/31850824/angularjs-force-browser-to-clear-cache – Marius Brits Nov 22 '16 at 13:22
-
javascript or angularjs whatever the best way. – Rinkal Garg Nov 22 '16 at 13:24
2 Answers
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!

- 10,494
- 4
- 30
- 50
-
2That';s the good solution. Don't forget to force refresh index.html using a meta tag and everything will work like a charm: http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers – Tonio Nov 22 '16 at 13:34
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.

- 1
- 1

- 403
- 5
- 23