-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load files in module only once #59
Comments
Sorry, this may end up being a duplicate of #58, I didn't check for new issues before posting since last time i searched on this. |
Not really a duplicate (#58 seems to be a bug). The specific part in the code is: angular.forEach(params.files, function(path) {
if(angular.isUndefined(filesCache.get(path)) || params.cache === false) {
if(/\.css[^\.]*$/.test(path) && cssFiles.indexOf(path) === -1) {
cssFiles.push(path);
} else if(/\.(htm|html)[^\.]*$/.test(path) && templatesFiles.indexOf(path) === -1) {
templatesFiles.push(path);
} else if (jsFiles.indexOf(path) === -1) {
jsFiles.push(path);
}
}
}); Are the paths similar or different in your case ? And as for modules, they shouldn't be reloaded, the specific code is: angular.forEach(module.requires, function(requireModule) {
if(regModules.indexOf(requireModule) === -1) {
requires.push(requireModule);
}
}); and also: // If this module has been loaded before, re-use it.
if(angular.isDefined(moduleName) && moduleExists(moduleName) && regModules.indexOf(moduleName) !== -1) {
moduleCache.push(moduleName);
[...] There are more parts of the code to check for this, but I didn't list them all. Do you have a more detailed example about this problem ? |
I have a use case akin to the above request where it would be helpful to expose publicly the moduleExists method already in the code. The code below is firing just fine on-authentication, however on-unauth, then re-auth (use case -> different user), the 'load' either dies or skips silently. Running a check to see if the modules exist in a different (auth) promise would enable the behaviour I think is requested above. $ocLazyLoad.load([{
module1
}, {
module2
}, {
module3
}, {
module4
}], {
cache: false,
reconfig: true
}).then(function() {
$rootScope.$broadcast('goToAuthDashboard');
}); Great tool btw. If you've got a beerware bucket somewhere, let me know |
Thanks, I'll make one :D The load function should not die silently, it probably rejects the promise, you need to add a second function in the "then" to get the rejects (or you can also use debug: true to see the errors in the console). .then(function success() {
$rootScope.$broadcast('goToAuthDashboard');
}, function error(err) {
console.log(err);
}); |
Actually, I repurposed what you already had and it seems to work well enough for my purposes:
|
Ok, I could make this function public, it's not like it would pose any kind of problem. About the donation, you can use Flattr |
Is there any built in way to restrict a module to loading only once? Not just not reconfiguring, but knowing that a module has already been loaded and not requesting it again? We currently work around this by maintaining a list of modules we've loaded and simply don't request if we've previously loaded.
I understand that this doesn't fit every use case (like when a module is loaded piece-by-piece) but it seems to be pretty handy functionality, especially when you have dependent modules.
The text was updated successfully, but these errors were encountered: