Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
62 changes: 0 additions & 62 deletions angular-cache-buster.js

This file was deleted.

7 changes: 5 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -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 <martin.saintmac@gmail.com>"
Expand All @@ -22,7 +22,10 @@
"node_modules",
"bower_components",
"test",
"tests"
"tests",
"gulpfile.js",
"karma.conf.js",
"package.json"
],
"devDependencies": {
"angular": "~1.2.13",
Expand Down
82 changes: 82 additions & 0 deletions dist/angular-cache-buster.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
}];
});

})();
1 change: 1 addition & 0 deletions dist/angular-cache-buster.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var minify = require('gulp-minify');

gulp.task('compress', function () {
gulp.src('lib/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(minify({
ext: {
src: '.js',
min: '.min.js'
},
exclude: ['tasks'],
ignoreFiles: ['.combo.js', '-min.js']
}))
.pipe(gulp.dest('dist'))
});
82 changes: 82 additions & 0 deletions lib/angular-cache-buster.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
}];
});

})();
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-cache-buster",
"version": "0.4.3",
"version": "0.5.3",
"description": "Cache Buster for AngularJS $http (and $resource). Especially useful with Internet Explorer (IE8, IE9)",
"main": "angular-cache-buster.js",
"scripts": {
Expand All @@ -22,22 +22,32 @@
"ie9"
],
"author": "saintmac <martin.saintmac@gmail.com> (Martin Saint-Macary, http://vyte.in)",
"contributors": ["Alfred Bratterud <alfred.bratterud@hioa.no>"],
"contributors": [
"Alfred Bratterud <alfred.bratterud@hioa.no>"
],
"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"
}
}