0

I know how to use compiler.clearCache(). However, it seems work only for HTML templates. Often, the browsers are still using the old javascript after I had updated the TS of the components. Currently I have to explicitly clear the browser cache, and then the users may have to do so as well.

Is there a better way in Angular2/4 to ensure using updated ts/js files?

ZZZ
  • 2,752
  • 2
  • 25
  • 37

1 Answers1

0

Disable Cache in browser setting is not a good approach since you don't wan to hit server for unchanged files. There are some why to tell browser that my code is updated so browser can fetch the latest code from server. I am a webpack user and webpack give you opportunity to hash your file names and only those been re compiled e.g you have a and b under development b is been updated to webpack will give new hashes to this file and unchanged file a fill have the same name so next time use visit browser he or she will get a from cache and b from servver since file name is been changed

output: {
        path: helpers.root('dist'),
        filename: "[name].[chunkhash].js",
        chunkFilename: "[name].[chunkhash].js"
},
Jorawar Singh
  • 7,463
  • 4
  • 26
  • 39