Force update of JavaScript file version

3

I'm developing an application in Angular2 and I'm facing a problem that is updating the JS files. When I update the version sometimes the browser does not load the new file, it uses the old one. I know if I put the version of the file at the end of the reference, like:

nomedoarquivo.js?v=1 works.

The problem is that js is not referenced directly in index.html as in Angular JS 1, files < in> JS are loaded through the SystemJS . Does anyone know a way to force it to always load the new JS , or version the JS using the SystemJS ?     

asked by anonymous 15.04.2016 / 14:41

1 answer

2

I think this problem in SystemJS is well-known: I found a issue under discussion in GitHub

In this Issue there is a possible WorkAround: a Gulp plugin called systemjs-cachebuster. If you're using Gulp, maybe it's a simple solution.

I also suggest that you evaluate lite-server . When I tested Angular2, I made use of the lite-server and I do not remember having problems with caching, and even hot-reloading helps a lot with the feedback cycle.

Installing lite-server in your project is simple using NPM:

npm install lite-server --save-dev

In your package.json simply adjust the "start" script or one of your preference.

"scripts": {
  "lite": "lite-server",  
},

Run with an npm run:

npm run lite

If you are using TypeScript, simply keep the compiler in - watch and lite-server will identify new versions of the Js files.

    
15.04.2016 / 15:46