r/angularjs • u/AshleyKang • Feb 25 '17
npm http-server keeps caching my AngularJS changes
I'm learning AngularJS 1.x. I'm using npm http-server to run the project locally.
The problem is, whenever I make changes to App.js the change doesn't get reflected on the site. I try refreshing the page, it doesn't update the changes to JS. I also tried serving with http-server -o -c-1 and still it doesn't refresh the cache.
The only thing that makes the App.js update is clearing the browser cache. How should I be doing this?
1
u/AshleyKang Feb 25 '17
Just found a better alternative to http-server.
npm install live-server -g
Then
<path> live server
No caching, and the site updates as soon as I save any file changes.
-2
u/Recoil42 Feb 25 '17
Any reason you're learning Angular 1.x over Angular2/4?
4
u/dejanribic Feb 26 '17
It is so much easier to learn...
0
1
u/AshleyKang Feb 25 '17
I'm deciding to spend 3 days each on Angular 1.x, Angular 2/4 and ReactJS just to get feel around different concepts.
Today I've moved onto ReactJS :)
0
u/Jessie_James Feb 26 '17 edited Feb 27 '17
FYI - From what I have heard, Angular 2 is drastically different than 1. Focus on 2 if you can.
2
u/AshleyKang Feb 27 '17
Well; let's say that in a job interview when they ask "Will you be a fundamental part of the team as we refactor from Angular 1 to 2", I will be able to confidently answer against my experience on both versions, my knowledge in difference between two frameworks and how I will go minimizing impact on the solution...etc etc etc. That's just one scenario.
1
1
u/sscotth Feb 26 '17 edited Feb 26 '17
I wrote a tiny express server to deal with this...
https://github.com/sscotth/node-static-stuff/blob/master/server.js
It's simply an express static server with no-cache headers applicable for all browsers.
http://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
7
u/[deleted] Feb 25 '17
If this is for develop cycle only, open Chrome Devtools, go to Network tab and tick "Disable cache" - this will work only when the Devtools panel is open (but can be in the background still).