Home > Web Front-end > JS Tutorial > body text

Simple implementation method of javascript file loading management_javascript skills

WBOY
Release: 2016-05-16 15:49:01
Original
1099 people have browsed it

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));

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!