Last active
September 10, 2020 12:54
-
-
Save ProLoser/6181026 to your computer and use it in GitHub Desktop.
Elegant cache-busting for AngularJS HTML assets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anglar.module('myApp',['ui']).config(["$provide", function($provide) { | |
return $provide.decorator("$http", ["$delegate", function($delegate) { | |
var get = $delegate.get; | |
$delegate.get = function(url, config) { | |
// Check is to avoid breaking AngularUI ui-bootstrap-tpls.js: "template/accordion/accordion-group.html" | |
if (!~url.indexOf('template/')) { | |
// Append ?v=[cacheBustVersion] to url | |
url += (url.indexOf("?") === -1 ? "?" : "&"); | |
url += "v=" + cacheBustVersion; | |
} | |
return get(url, config); | |
}; | |
return $delegate; | |
}]); | |
}]); |
not to be a jerk but typo on line 1 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Thank you for writing this. It has really helped me. I was just wondering if anyone could help in getting my Karma test to work for this? I am using the server to create a cache bust constant every time I run a build. I then pass this constant into the .config.
I have tried adding it where the constants required in a service would go, but I guess that the Constant needs to get to the module prior to running a service as it runs during the configuration phase?
Any ideas would be much appreciated.