Closed kayhadrin closed 9 years ago
Hi David,
I completely agree with you. This is a great solution and I'm sure it will make the preload feature better.
Do you mind submitting a pull request with these changes? I'll be happy to merge it.
Thank you for your contribution!
Alex Castillo
Hi @kayhadrin
I've pushed a fix based on your suggestions. Please review.
Best,
Alex
Thanks @alexandercastillo. It looks fine to me.
Just wondering why you use the parse(stylesheet)
instruction now?
Is it because stylesheet
could be a string representation of an angular hash object?
@kayhadrin I use parse(stylesheet)
so the stylesheets argument in the callback contain the rest of the properties AngularCSS is adding internally. I think that could be relevant to the developer.
Hi there,
I was reviewing this promising angular module and found a small algorithm issue in the
$css.preload()
function.Here's the original function code:
I can see that
angular.forEach(stylesheets, ...
will make the program download each stylesheet by ajax, and for each stylesheet download success, we'll run thecallback
function only when we downloaded the last stylesheet in the list.For me, the problem is that we assumed that stylesheets will be loaded in sequential order. However, due to the nature of ajax requests and the unpredictable response speed of servers, this cannot be guaranteed.
So I think this part of the algorithm should take advantage of promises to make sure that the callback function is called at the end when all stylesheets have been loaded successfully.
So here's my suggested code change:
Please let me know what you think.
Regards,
David