-
Notifications
You must be signed in to change notification settings - Fork 1.4k
prevent multiple loading of the same template. #1301
Conversation
|
I'd rather keep using the |
|
Its still using the $templateCache. This fix should resolve this open issue: The solution he is using there is just a hack. |
|
Since this is used in multiple places, maybe refactor it into a helper service? |
|
yes, |
|
Ah, sorry, looks like you could just keep the element in the templates array to avoid going into $q.when again. Just saw similar usage yesterday from awesome $q presentation at ng-europe: http://youtu.be/33kl0iQByME?t=13m54s |
|
Nice.. |
|
I'm not sure you need an array/map to begin with, that's redundant to what |
|
The array is just for storing the promises, not the templates themselves, so if the second request is made before the first promise fulfills, it won't trigger the $http loading of the template, it just returns the previous stored promise, and when the original $http request finishes, all the pending requests will resolve. |
|
Got it, indeed squashing requests is a good idea and that's not covered by |
|
Finally implemented this without a separate helper as it would be a breaking change for any project requiring specific files of the build. Though it might be worth a refactor in the future. |
|
The fetchPromises cache prevents client code from updating $templateCache manually and having the new template being used from now on |
|
@lopex looks like this might be a bug, could you please open a new issue? |
The issue is that the same template was loaded as mush as the directive was used.
My assumption is that the templateCache service didn't had a chance to save the template from the first fetch so he keep sending http requests each time.
solution:
save array of the promises and just if the template key is not in the array, fetch it.