Problems refreshing angularjs changes on production server

All we need is an easy explanation of the problem, so here it is.

I have a recurring issue that occurs when I make changes to my angularjs app. The problem is that I have to refresh the page if I want to seed the changes that I have made. This is a problem, because I don’t want my users to have to refresh the page (they may not know to do this). They may think the site is broken. Is there some kind of angular directive or process that I can follow that will allow my UI changes to be reflected on my production server without my users having to refresh the page?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

There are a couple of solutions you could look at,

  1. There is a similar answer to your question here:

AngularJS disable partial caching on dev machine

To quote the accepted answer on that post:

“here’s one way to always automatically clear the cache whenever the
ng-view content changes”$rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
  1. A non angular solution may also be found here:

Force browser to clear cache

To quote the best answer on that post (Fermin’s answer):

If it’s to view css or js changes one way is to append _versionNo to
the css/js file for each release. E.g.

script_1.0.css script_1.1.css script_1.2.css etc.

You can check out this link to see how it could work.

I hope these help.

To respond to your comment, I’m sorry the above hasn’t worked.

Perhaps you could try implementing a websockets based approach, similar to Trello, whereby after a certain amount of time you ask the user to update their page to receive new updates to the system or to refresh if their socket connection has timed out? Depending on your setup you may find this tutorial useful:

Method 2

Using html2js you can more easily manage versioning of templates. It is a grunt plugin that will load all of your templates into a js file. Downside is all your templates get loaded regardless of need, upside is you have all your templates loaded ready to use on one http call and one point of caching for them. This way you can set up to rename your js file on new releases and bust the cache for templates on production. As for dev, the other answer here is sufficient.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply