diff --git a/README.md b/README.md index 23cf042..a517bd8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,18 @@ Cache Buster for Angular JS $http and $resource. Especially useful with Internet Explorer (IE8, IE9) +This repository is forked from + # install - bower install angular-cache-buster --save +Add this to your bower.json file. + + { + "dependencies": { + "angular-cache-buster": "https://github.com/j-combee/angular-cache-buster.git#0.5.3" + } + } + In your app module definition, add `ngCacheBuster` as a dependency @@ -17,17 +26,28 @@ Since you probably want to maintain browser caching for your views, partials or For instance, if you want to bust everything except views in a 'partials' folder and images in a 'images' folder , you can configure AngularCacheBuster this way: angular.module('yourApp', ['ngCacheBuster']) - .config(function(httpRequestInterceptorCacheBusterProvider){ + .config(['httpRequestInterceptorCacheBusterProvider', function(httpRequestInterceptorCacheBusterProvider){ httpRequestInterceptorCacheBusterProvider.setMatchlist([/.*partials.*/,/.*images.*/]); - }); + }]); If instead you want to allow everything to be cached, except your "/api/users" and "api/orders" (assuming they are the only things that change frequently), you can supply a matchlist as before, but pass in a second boolean argument "blacklist" set to true as well: angular.module('yourApp', ['ngCacheBuster']) - .config(function(httpRequestInterceptorCacheBusterProvider){ + .config(['httpRequestInterceptorCacheBusterProvider', function(httpRequestInterceptorCacheBusterProvider){ httpRequestInterceptorCacheBusterProvider.setMatchlist([/.*orders.*/,/.*users.*/],true); - }); + }]); + +If you have a personal key that you want to append on the url you can set that key like this. + + + angular.module('yourApp', ['ngCacheBuster']) + .config(['httpRequestInterceptorCacheBusterProvider', function(httpRequestInterceptorCacheBusterProvider){ + httpRequestInterceptorCacheBusterProvider.setMatchlist([/.*orders.*/,/.*users.*/],true).setCustomKey('YourOwnKey'); + }]); + +This is used for versioning. + # use diff --git a/angular-cache-buster.js b/angular-cache-buster.js deleted file mode 100644 index a368a50..0000000 --- a/angular-cache-buster.js +++ /dev/null @@ -1,62 +0,0 @@ -angular.module('ngCacheBuster', []) - .config(['$httpProvider', function($httpProvider) { - return $httpProvider.interceptors.push('httpRequestInterceptorCacheBuster'); - }]) - .provider('httpRequestInterceptorCacheBuster', function() { - - this.matchlist = [/.*partials.*/, /.*views.*/ ]; - this.logRequests = false; - - //Default to whitelist (i.e. block all except matches) - this.black=false; - - //Select blacklist or whitelist, default to whitelist - this.setMatchlist = function(list,black) { - this.black = typeof black != 'undefined' ? black : false - this.matchlist = list; - }; - - - this.setLogRequests = function(logRequests) { - this.logRequests = logRequests; - }; - - this.$get = ['$q', '$log', function($q, $log) { - var matchlist = this.matchlist; - var logRequests = this.logRequests; - var black = this.black; - if (logRequests) { - $log.log("Blacklist? ",black); - } - return { - 'request': function(config) { - //Blacklist by default, match with whitelist - var busted= !black; - - for(var i=0; i< matchlist.length; i++){ - if(config.url.match(matchlist[i])) { - busted=black; break; - } - } - - //Bust if the URL was on blacklist or not on whitelist - if (busted) { - var d = new Date(); - config.url = config.url.replace(/[?|&]cacheBuster=\d+/,''); - //Some url's allready have '?' attached - config.url+=config.url.indexOf('?') === -1 ? '?' : '&' - config.url += 'cacheBuster=' + d.getTime(); - } - - if (logRequests) { - var log='request.url =' + config.url - busted ? $log.warn(log) : $log.info(log) - } - - return config || $q.when(config); - } - } - }]; - }); - - diff --git a/bower.json b/bower.json index 57187ed..56193b5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-cache-buster", - "version": "0.4.3", + "version": "0.5.3", "homepage": "https://github.com/saintmac/angular-cache-buster", "authors": [ "saintmac " @@ -22,7 +22,10 @@ "node_modules", "bower_components", "test", - "tests" + "tests", + "gulpfile.js", + "karma.conf.js", + "package.json" ], "devDependencies": { "angular": "~1.2.13", diff --git a/dist/angular-cache-buster.js b/dist/angular-cache-buster.js new file mode 100644 index 0000000..01f44b7 --- /dev/null +++ b/dist/angular-cache-buster.js @@ -0,0 +1,82 @@ +(function () { + 'use strict'; + + angular.module('ngCacheBuster', []) + .config(['$httpProvider', function ($httpProvider) { + return $httpProvider.interceptors.push('httpRequestInterceptorCacheBuster'); + }]) + .provider('httpRequestInterceptorCacheBuster', function () { + + this.matchlist = [/.*partials.*/, /.*views.*/]; + this.logRequests = false; + + //Default to whitelist (i.e. block all except matches) + this.black = false; + + //Optional custom bust key + this.key = false; + + //Select blacklist or whitelist, default to whitelist + this.setMatchlist = function (list, black) { + this.black = typeof black != 'undefined' ? black : false; + this.matchlist = list; + }; + + //Set a custom bust key to bust the cache + this.setCustomKey = function (key) { + this.key = key; + }; + + + this.setLogRequests = function (logRequests) { + this.logRequests = logRequests; + }; + + this.$get = ['$q', '$log', function ($q, $log) { + var matchlist = this.matchlist; + var logRequests = this.logRequests; + var black = this.black; + var key = this.key; + if (logRequests) { + $log.log("Blacklist? ", black); + } + return { + 'request': function (config) { + //Blacklist by default, match with whitelist + var busted = !black; + + for (var i = 0; i < matchlist.length; i++) { + if (config.url.match(matchlist[i])) { + busted = black; + break; + } + } + + //Bust if the URL was on blacklist or not on whitelist + if (busted) { + if (!key) { + var d = new Date(); + key = d.getTime(); + } + config.url = config.url.replace(/[?|&]cacheBuster=\d+/, ''); + //Some url's allready have '?' attached + config.url += config.url.indexOf('?') === -1 ? '?' : '&'; + config.url += 'cacheBuster=' + key; + } + + if (logRequests) { + var log = 'request.url =' + config.url; + if (busted) { + $log.warn(log); + } else { + $log.info(log); + } + } + + return config || $q.when(config); + } + }; + }]; + }); + +})(); diff --git a/dist/angular-cache-buster.min.js b/dist/angular-cache-buster.min.js new file mode 100644 index 0000000..0059d6b --- /dev/null +++ b/dist/angular-cache-buster.min.js @@ -0,0 +1 @@ +!function(){"use strict";angular.module("ngCacheBuster",[]).config(["$httpProvider",function(t){return t.interceptors.push("httpRequestInterceptorCacheBuster")}]).provider("httpRequestInterceptorCacheBuster",function(){this.matchlist=[/.*partials.*/,/.*views.*/],this.logRequests=!1,this.black=!1,this.key=!1,this.setMatchlist=function(t,e){this.black="undefined"!=typeof e?e:!1,this.matchlist=t},this.setCustomKey=function(t){this.key=t},this.setLogRequests=function(t){this.logRequests=t},this.$get=["$q","$log",function(t,e){var s=this.matchlist,i=this.logRequests,r=this.black,u=this.key;return i&&e.log("Blacklist? ",r),{request:function(n){for(var h=!r,c=0;c (Martin Saint-Macary, http://vyte.in)", - "contributors": ["Alfred Bratterud "], + "contributors": [ + "Alfred Bratterud " + ], "license": "MIT", "bugs": { "url": "https://github.com/saintmac/angular-cache-buster/issues" }, "homepage": "https://github.com/saintmac/angular-cache-buster", "devDependencies": { - "karma-script-launcher": "~0.1.0", + "gulp": "^3.9.1", + "gulp-cli": "^1.2.1", + "gulp-jshint": "^2.0.1", + "gulp-minify": "0.0.11", + "jshint": "^2.9.2", + "karma": "~0.12.15", "karma-chrome-launcher": "~0.1.3", + "karma-coffee-preprocessor": "~0.1.3", "karma-firefox-launcher": "~0.1.3", "karma-html2js-preprocessor": "~0.1.0", "karma-jasmine": "~0.1.5", - "karma-coffee-preprocessor": "~0.1.3", - "requirejs": "~2.1.11", - "karma-requirejs": "~0.2.1", "karma-phantomjs-launcher": "~0.1.2", - "karma": "~0.12.15" + "karma-requirejs": "~0.2.1", + "karma-script-launcher": "~0.1.0", + "requirejs": "~2.1.11" + }, + "directories": { + "test": "test" } }