Home  >  Article  >  Web Front-end  >  Simple implementation method of javascript file loading management_javascript skills

Simple implementation method of javascript file loading management_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:49:011072browse

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
dcc41216e4f29be3b28d7de3316740662cacc6d41bbb37262a98f745aa00fbf0
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn