Force Javascript File Version Update

Asked

Viewed 499 times

3

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

nomedoarquivo.js?v=1 works.

The problem is that in Angular2 the files are not referenced js directly on index.html as in Angular JS 1, the files JS are loaded through the Systemjs. Someone knows a way to force him to always carry the JS new, or Versionar the JS using the Systemjs?

  • The answer solves your problem?

1 answer

2


I believe this problem in Systemjs is known: I found a Debate on the Github

In this issue there is a possible Workaround: a Gulp plugin called systemjs-cachebuster. If you are using Gulp, it may be a simple solution.

I also suggest that you evaluate the lite-server. When I tested Angular2, I made use of lite-server and I don’t remember having encountered problems with cache and even hot-Reloading helps a lot with the feedback cycle.

Installing the 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 own.

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

Run with an npm run:

npm run lite

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.