0

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

Rinkal Garg
  • 62
  • 1
  • 10

2 Answers2

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!

Dave Cooper
  • 10,494
  • 4
  • 30
  • 50
  • 2
    That';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
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.

Community
  • 1
  • 1
Massi Issar
  • 403
  • 5
  • 23