angularjs - Change source url on $includeContentRequested -


I want to change the URL for each time a ng-included instruction partial requests. Up to now, I can see the URL and this type of incident:

  app.run (function ($ rootsecope) {$ at $ Rootscope. $ ('$ IncludeContentRequested', function (event) , Url) {console.log (event); console.log (url);});});  

Now I should be able to change the URL from 'templates / incs / includedPartial.html' to 'templates / incs / includedPartial.html. ? Cache_version = 1_1 ', then include partially with the new link.

Obviously I'm doing this to prevent caching problems on version changes. Is this a good strategy or a better solution? Thanks in advance for any help ...

I think I really know the answer have put. What you can do to create an interceptor since all requests with NG actually go through the normal $ httpProvider, so you can block the request and add a cache booster.

  app.factory ("cacheBusterFactory", ["VERSION", function (VERSION) {return {request: function (configuration) {if (config.url.indexOf (".html", Config.url.length - ".html" .length)! == -1) {config.url + "? V =" + VERSION.toString ();} return conversion;}};}]);  

In this case "VERSION" is an angle constant that I change on each deployment:

  app.constant ("VERSION", 0.1);  

And adding a cache booster is as simple:

  .config (["$ httpProvider", function ($ httpProvider) {$ httpProvider.interceptors .push ("CacheBusterFactory");}])  

As you can see, I only block .html files, because only those people need to add me the cash busting. You can expand or rebuild "CashBuster Factory" according to your needs.


Comments