Handle cache with Angularjs

Asked

Viewed 1,444 times

0

I have an app with AngularJs, application when I make any changes and then the deploy the browser does not recognize these changes. It only works when I change the URL of that application.

I received some tips here on SOpt to use querystring with Timestamp, but I would like to try to solve this problem using something AngularJS

Would you have some way to disable or treat the cache so that this problem doesn’t happen?

  • The Angularjs is a Javascript framework, you will not be able to solve your cache problem in the client-side, the ideal would be to establish the expiration time of the files on the server.

  • And as for this: http://opensourcesoftwareandme.blogspot.com.br/2014/02/safely-prevent-template-caching-in-angularjs.html

  • Would not work?

  • Your cache is from template or.js files?

  • From template, if I add a menu and do deploy this menu does not appear unless I clear the cache.

1 answer

1

Browser does not recognize, because precisely the script AngularJs.js already exists in the browser cache. For any script to be reloaded, why don’t you try using window.location.reload(true). Should you wish an alternative, I would advise you to perform a function rand() the moment you carry the AngularJs.js and add as "parameter" GET, so always the path will be "changed" and the browser will understand that is to download this new script.

Example with PHP:

<script src=\"AngularJs.js?r=<?php echo rand(0,10); ?>" type=\"text/javascript\"></script>

Browser other questions tagged

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