urish / angular-load

Dynamically load scripts and css stylesheets in your Angular.JS app
MIT License
243 stars 65 forks source link

Re-load or unload script? #15

Open maeishoj opened 9 years ago

maeishoj commented 9 years ago

Hi, I am in a situation where I need to either force a reload of a script, or unload and load it again.

Is there a way to add this?

vaneshmali commented 8 years ago

same here i want!

ganmedia commented 8 years ago

Same here, any idea?

soumak77 commented 8 years ago

I've been using this solution to do this: http://stackoverflow.com/a/9425964

soumak77 commented 8 years ago

There seems to be an intermittent issue with attempting to unload the file after loading it through angularLoad. As long as there is a significant amount of time between unloading/loading, things work as expected. However, when attempting to load/unload files quickly, angularLoad can get into a scenario where the file reference is still in the promise cache (i.e. promises[url] is defined), but isn't loaded in the DOM. This causes angularLoad to skip creation of the element and therefore the file is not reloaded as expected.

In order to resolve this issue, angularLoad would have to be aware of when the element it created is removed from the DOM. There don't appear to be any cross-browser solutions for knowing when an element is removed from the DOM, so it doesn't seem possible for angularLoad to know this automatically. As a result, a new method would have to be added to inform angularLoad that the script it loaded previous has been unloaded.

It would seem strange to expose a new method for angularLoad that simply notifies it when a script has been unloaded. Unloading of the script should really be the job of the angularLoad module itself. I'll look into creating a PR with exposes an unloadScript and unloadCSS methods, using the solution provided in the link above.

@urish would you be open to using this solution or do you have suggestions on other solutions to unload css and js files?