0

When I made changes in any template (html) in my code and refresh from browser then the changes does not occur in application.

I want to bypass template cache when I made changes in any template i.e I want when I make any changes in template and refresh from browser then the code should be updated code not from $templateCache.

And how could I know that there is any changes in template programmatically?

I have tried this code too from Stackoverflow reference.

app.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function($event) {
       console.log($event);
       alert("abc");
      //$templateCache.removeAll();
        $templateCache("templates").removeAll();
   });
});
2
  • 1
    Is it possible that the browser does caching? Commented Sep 9, 2015 at 6:37
  • Yes, browser does, most of the time. Especially IE. Commented Sep 9, 2015 at 6:45

2 Answers 2

1

I assume this is due to you actively working on the webpage and want to see your changes immediately, and not something you actually need for production? If so, then you could just turn off the cache in your browser. In chrome you do this by going to developer tools -> Settings -> General and tick 'Disable cache (while DevTools is open)

Sign up to request clarification or add additional context in comments.

1 Comment

I don't want to disable cache since a lot of thing is dependent on cache and performance issue too. And we can't say to client to use ctrl+f5 / ctrl+shift+R to refresh the application.
0

It's possible that the browser does some caching regardless of your logic.

Try sending the header: Cache-Control: no-cache (section 14.9) if you never want a request cached.

no-cache:

If the no-cache directive does not specify a field-name, then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server. This allows an origin server to prevent caching even by caches that have been configured to return stale responses to client requests.

For development you can also disable the cache in the browser, or use ctrl+f5/ctrl+shift+R or the key combination for your browser/os which will forcefully reload the page bypassing the cache.

5 Comments

I don't want to disable cache since a lot of thing is dependent on cache and performance issue too. And we can't say to client to use ctrl+f5 / ctrl+shift+R to refresh the application.
If all you want is to refresh the browser's cache entry it should be a simple key combination.
Can I remove the cache of the all templates or the template in which I made changes...?
If you're on a specific page you can refresh the requests from this page, which should effectively refresh only what is relevant in this page (including the specific request that generated the content).
I think you can use a request interceptor and add parameter to over come browser caching, checkout this question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.