Organizational Research By

Surprising Reserch Topic

dynamically load a javascript file


dynamically load a javascript file  using -'javascript,file,import,include'

How can you reliably and dynamically load a JavaScript file?  This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand.

The client that uses the component isn't required to load all the library script files (and manually insert <script> tags into their web page) that implement this component - just the 'main' component script file.

How do mainstream JavaScript libraries accomplish this (Prototype, jQuery, etc)?  Do these tools merge multiple JavaScript files into a single redistributable 'build' version of a script file?  Or do they do any dynamic loading of ancillary 'library' scripts?

An addition to this question: is there a way to handle the event after a dynamically included JavaScript file is loaded?  Prototype has document.observe for document-wide events. Example:

document.observe("dom:loaded", function() {
  // initially hide all containers for tab content
  $$('div.tabcontent').invoke('hide');
});


What are the available events for a script element?
    

asked Sep 10, 2015 by GloryCAQwdnp
0 votes
39 views



Related Hot Questions

17 Answers

0 votes
NULL
answered Sep 10, 2015 by LettieGillan
0 votes
NULL
answered Sep 10, 2015 by PhiTYG
0 votes
NULL
answered Sep 10, 2015 by MKGLar
0 votes
NULL
answered Sep 10, 2015 by EvaMenkens
0 votes
NULL
answered Sep 10, 2015 by SilasBeamont
0 votes
NULL
answered Sep 10, 2015 by ThomasKinche
0 votes
NULL
answered Sep 10, 2015 by RaeScholzzvb
0 votes
NULL
answered Sep 10, 2015 by KatScoggins
0 votes
NULL
answered Sep 10, 2015 by SheOneill
0 votes
NULL
answered Sep 10, 2015 by ValTorreggi
0 votes
NULL
answered Sep 10, 2015 by ZulStonehav
0 votes
NULL
answered Sep 10, 2015 by StaElphinst
0 votes
NULL
answered Sep 10, 2015 by GeraldCherry
0 votes
NULL
answered Sep 10, 2015 by oraexactabucuresti
0 votes
NULL
answered Sep 10, 2015 by LeaBenham
0 votes
NULL
answered Sep 10, 2015 by SherleneXRMn
0 votes
NULL
answered Sep 10, 2015 by DavidSticht

...