Dynamically load a JavaScript file

后端 未结 28 3380
说谎
说谎 2020-11-22 06:56

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 dynamical

28条回答
  •  日久生厌
    2020-11-22 07:27

    There are scripts that are designed specifically for this purpose.

    yepnope.js is built into Modernizr, and lab.js is a more optimized (but less user friendly version.

    I wouldn't reccomend doing this through a big library like jquery or prototype - because one of the major benefits of a script loader is the ability to load scripts early - you shouldn't have to wait until jquery & all your dom elements load before running a check to see if you want to dynamically load a script.

提交回复
热议问题