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
22 changes: 22 additions & 0 deletions dist/modules/ocLazyLoad.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
$provide: $provide, // other things (constant, decorator, provider, factory, service)
$injector: $injector,
$animateProvider: $animateProvider
},
cacheBuster = function cacheBuster(url) {
var dc = Date.now();
if (url.indexOf('?') >= 0) {
if (url.substring(0, url.length - 1) === '&') {
return url + '_dc=' + dc;
}
return url + '&_dc=' + dc;
} else {
return url + '?_dc=' + dc;
}
},
debug = false,
events = false,
Expand Down Expand Up @@ -55,6 +66,10 @@
if (angular.isDefined(config.events)) {
events = config.events;
}

if (angular.isDefined(config.cacheBuster)) {
cacheBuster = config.cacheBuster;
}
};

/**
Expand Down Expand Up @@ -393,6 +408,13 @@
return filesCache;
},

/**
* Used to generate urls to invalidate the cache
* @param url
* @returns {string}
*/
cacheBuster: cacheBuster,

/**
* Let the service know that it should monitor angular.module because files are loading
* @param watch boolean
Expand Down
25 changes: 10 additions & 15 deletions dist/modules/ocLazyLoad.loaders.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@
el,
loaded,
filesCache = $delegate._getFilesCache(),
cacheBuster = function cacheBuster(url) {
var dc = new Date().getTime();
if (url.indexOf('?') >= 0) {
if (url.substring(0, url.length - 1) === '&') {
return url + '_dc=' + dc;
}
return url + '&_dc=' + dc;
} else {
return url + '?_dc=' + dc;
}
};
cacheBuster = $delegate.cacheBuster;

// Store the promise early so the file load can be detected by other parallel lazy loads
// (ie: multiple routes on one page) a 'true' value isn't sufficient
Expand Down Expand Up @@ -79,6 +69,7 @@

/*
The event load or readystatechange doesn't fire in:
- PhantomJS 1.9 (headless webkit browser)
- iOS < 6 (default mobile browser)
- Android < 4.4 (default mobile browser)
- Safari < 6 (desktop browser)
Expand All @@ -87,16 +78,20 @@
if (!uaCssChecked) {
var ua = $window.navigator.userAgent.toLowerCase();

// iOS < 6
if (/iP(hone|od|ad)/.test($window.navigator.platform)) {
if (ua.indexOf('phantomjs/1.9') > -1) {
// PhantomJS ~1.9
useCssLoadPatch = true;
} else if (/iP(hone|od|ad)/.test($window.navigator.platform)) {
// iOS < 6
var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.'));
useCssLoadPatch = iOSVersion < 6;
} else if (ua.indexOf("android") > -1) {
} else if (ua.indexOf('android') > -1) {
// Android < 4.4
var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8));
var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8));
useCssLoadPatch = androidVersion < 4.4;
} else if (ua.indexOf('safari') > -1) {
// Safari < 6
var versionMatch = ua.match(/version\/([\.\d]+)/i);
useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6;
}
Expand Down
5 changes: 5 additions & 0 deletions dist/modules/ocLazyLoad.loaders.templatesLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
angular.forEach(paths, function (url) {
var deferred = $q.defer();
promises.push(deferred.promise);

if (params.cache === false) {
url = $delegate.cacheBuster(url);
}

$http.get(url, params).success(function (data) {
if (angular.isString(data) && data.length > 0) {
angular.forEach(angular.element(data), function (node) {
Expand Down
52 changes: 37 additions & 15 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
$provide: $provide, // other things (constant, decorator, provider, factory, service)
$injector: $injector,
$animateProvider: $animateProvider
},
cacheBuster = function cacheBuster(url) {
var dc = Date.now();
if (url.indexOf('?') >= 0) {
if (url.substring(0, url.length - 1) === '&') {
return url + '_dc=' + dc;
}
return url + '&_dc=' + dc;
} else {
return url + '?_dc=' + dc;
}
},
debug = false,
events = false,
Expand Down Expand Up @@ -62,6 +73,10 @@
if (angular.isDefined(config.events)) {
events = config.events;
}

if (angular.isDefined(config.cacheBuster)) {
cacheBuster = config.cacheBuster;
}
};

/**
Expand Down Expand Up @@ -400,6 +415,13 @@
return filesCache;
},

/**
* Used to generate urls to invalidate the cache
* @param url
* @returns {string}
*/
cacheBuster: cacheBuster,

/**
* Let the service know that it should monitor angular.module because files are loading
* @param watch boolean
Expand Down Expand Up @@ -825,17 +847,7 @@
el,
loaded,
filesCache = $delegate._getFilesCache(),
cacheBuster = function cacheBuster(url) {
var dc = new Date().getTime();
if (url.indexOf('?') >= 0) {
if (url.substring(0, url.length - 1) === '&') {
return url + '_dc=' + dc;
}
return url + '&_dc=' + dc;
} else {
return url + '?_dc=' + dc;
}
};
cacheBuster = $delegate.cacheBuster;

// Store the promise early so the file load can be detected by other parallel lazy loads
// (ie: multiple routes on one page) a 'true' value isn't sufficient
Expand Down Expand Up @@ -885,6 +897,7 @@

/*
The event load or readystatechange doesn't fire in:
- PhantomJS 1.9 (headless webkit browser)
- iOS < 6 (default mobile browser)
- Android < 4.4 (default mobile browser)
- Safari < 6 (desktop browser)
Expand All @@ -893,16 +906,20 @@
if (!uaCssChecked) {
var ua = $window.navigator.userAgent.toLowerCase();

// iOS < 6
if (/iP(hone|od|ad)/.test($window.navigator.platform)) {
if (ua.indexOf('phantomjs/1.9') > -1) {
// PhantomJS ~1.9
useCssLoadPatch = true;
} else if (/iP(hone|od|ad)/.test($window.navigator.platform)) {
// iOS < 6
var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.'));
useCssLoadPatch = iOSVersion < 6;
} else if (ua.indexOf("android") > -1) {
} else if (ua.indexOf('android') > -1) {
// Android < 4.4
var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8));
var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8));
useCssLoadPatch = androidVersion < 4.4;
} else if (ua.indexOf('safari') > -1) {
// Safari < 6
var versionMatch = ua.match(/version\/([\.\d]+)/i);
useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6;
}
Expand Down Expand Up @@ -1245,6 +1262,11 @@
angular.forEach(paths, function (url) {
var deferred = $q.defer();
promises.push(deferred.promise);

if (params.cache === false) {
url = $delegate.cacheBuster(url);
}

$http.get(url, params).success(function (data) {
if (angular.isString(data) && data.length > 0) {
angular.forEach(angular.element(data), function (node) {
Expand Down
Loading