0

I would like to know the efficient way to dynamically load and unload Javascript plugins depending on options toggled on and off by the user.

Also, I was wondering if all the resources will really be freed if I simply remove the <script id="pluginId"> tag from the DOM ?

Thank you!

5
  • When you include a Javascript file, the state of the page is potentially changed. I doubt there is a way to "unload" a Javascript plugin/file. Commented Feb 24, 2011 at 17:20
  • See stackoverflow.com/questions/1346897/… Commented Feb 24, 2011 at 17:22
  • Though if everything is attached to a namespace, you could potentially null everything out. Watch out for the memory leaks though. Commented Feb 24, 2011 at 17:23
  • 1
    When deleting a <script> tag, I can still access the functions which are inside that .js file. Commented Feb 24, 2011 at 17:28
  • Great information guys ! Commented Feb 24, 2011 at 17:47

1 Answer 1

-1

You can create a script tag and insert it into the DOM in the header:

 var head= document.getElementsByTagName('head')[0];
 var script= document.createElement('script');
 script.type= 'text/javascript';
 script.src= 'helper.js';
 head.appendChild(script);

Snippet from http://unixpapa.com/js/dyna.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.