The example in this article describes a simple implementation method of javascript file loading management. Share it with everyone for your reference. The details are as follows:
Here is a super simple way to load and manage JavaScript files (modules),
To implement the core functions of sea.js or require.js, use one line
Load all js files.
//按照lightJs的顺序,让网页加载js文件: var lightJs = [ "./js/light/pre/jquery-1.8.0.min.js", "./js/light/pre/jquery-lib.js", "./js/light/pre/less-1.4.2.min.js", "./js/lihgt/pre/util.js", "./js/xla.js", "./js/light/light_file.js" ]; var light; if (!light) light = {}; light.load = (function(lightJs) { if (!lightJs) lightJs = []; var doc = document; var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement; for (var i = 0; i < lightJs.length; i++) { var path = lightJs[i]; var node = doc.createElement("script"); node.charset = "utf-8"; node.src = path; head.appendChild(node); } return doc; }(lightJs));
I hope this article will be helpful to everyone’s JavaScript programming design.