Skip to content

Instantly share code, notes, and snippets.

@singhmohancs
Forked from ProLoser/AngularJS-Cachebusting.js
Created November 30, 2016 19:25
Show Gist options
  • Save singhmohancs/b0b77690dc40ae4e6e240d0594525003 to your computer and use it in GitHub Desktop.
Save singhmohancs/b0b77690dc40ae4e6e240d0594525003 to your computer and use it in GitHub Desktop.
Elegant cache-busting for AngularJS HTML assets
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;
}]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment