muratcorlu / ngx-script-loader

Angular 3rd party script loader
MIT License
33 stars 6 forks source link

Failed loads will get appended to the first target element on successive retries. #9

Open dramentol opened 6 years ago

dramentol commented 6 years ago

Hi,

Let's say I call loadScript for a url and a target element A and it fails. Then I call again for the same url but target element B. In this case, the script gets appended to element A. And element A may not even be in the dom anymore.

This happens for example when using ngx-script-loader component in a component.

My workaround is to delete the entry from scriptsLoaders map on error.

muratcorlu commented 6 years ago

Hmm, good catch. This is because we are caching script loaders by their url. But it looks like we should also care targetElement and even attributes parameters while we are checking cache. A PR will be very welcome or I'll try to fix this when I find some time next week.

dramentol commented 6 years ago

Not sure about that. If you cache by url + target element you run the risk of multiple loads for the same script.

I don't see any reason to cache failed loads.