My module Loading System v4

Source: Internet
Author: User

This version adds the following features:

    • Supports negative callback when loading fails. Since opera sends a fatal error when processing the Invalid Address of the request, it cannot be captured by onerror or so on, so my negative callback does not work for it (the test browser is opera11 ). However, I can simulate script. onerror in IE, which is the biggest advantage of my loader over other loaders and the biggest highlight of this version.

      Dom. Require (dependlist, callback,/* optional */errback) // dependency list, positive callback, negative callback
    • If the request address is invalid, the timer is immediately suspended to prevent endless setTimeout.
    • Add more rigorous detection to prevent repeated requests.

For API and usage, see the third edition:

// Parallel loader by situ zhengmei 2011.3.1; (function (Win, Dom, undefined) {var reg_module_name = /(?: ^ | \/) ([^ (\/] + )(? = \ (| $)/, Reg_module_url =/\ ([^)] +) \)/, reg_readystate =/loaded | complete/I, scripts = Dom. getelementsbytagname ("script"), bases = Dom. getelementsbytagname ("base"), _ dom = win. dom, dom = {mix: function (target, source, override) {var I, ride = (override = void 0) | override; for (I in source) {If (ride |! (I in target) {target [I] = source [I] ;}} return target ;}, noconflict: function () {// prevents name conflicts, please reference other libraries before referencing this framework win. DOM = _ Dom; // This is another person's return Dom; // please assign it a namespace}, require: function (/* array or string */dependlist, callback, /* optional */errback) {var self = arguments. callee, modulenames = [], I = 0, hash = self. loadedmodules, Reg = reg_module_name, name, URL; If (typeof dependlist = "string") {dependlist = Dependlist. Split (",")} while (url = dependlist [I ++]) {name = URL. Match (REG) [1]; If (! Hash [name]) {callback. errback = errback | function () {} callback. name = Name; callback. url = URL; modulenames. push (name); self. appendscript (callback) ;}} this. provide (modulenames, hash, callback)}, define: function (name, dependlist, callback) {var hash = This. require. loadedmodules, node = Dom. getelementbyid ("_" + name + "_"); If (node) {node [name] + = "_ loaded"} This. require (dependlist, function () {callbac K (); hash [name] = 1})}, // provides the module provide: function (array, hash, callback) {var flag = true, I = 0, ARGs = arguments, FN = args. callee, name; while (name = array [I ++]) {If (! Hash [name]) {flag = false; break ;}}if (FLAG) {callback () ;}else {callback. timeoutid = setTimeout (function () {fn. apply (null, argS)}, 32) ;}} Dom. mix (Dom. require, {loadedmodules :{}, requestedurl :{}, // http://www.cnblogs.com/rubylouvre/archive/2011/02/10/1950940.html getbasepath: function (/* internal */url,/* internal */node) {try {. b. C ()} catch (e) {url = E. filename | E. sourceurl; // applicable to Firefox and Safari} If (! URL) {node = scripts [scripts. Length-1] url = node. hasattribute? Node. SRC: node. getattribute ('src', 4);} url = URL. substr (0, URL. lastindexof ('/'); Dom. require. getbasepath = function () {return URL; // cache the result. The result is returned directly after the first time. You do not need to calculate} return URL;}, appendscript: function (OBJ, /* internal */URL) {// process Dom. node (http://www.cnblogs.com/rubylouvre/dom/node.js) Case VaR _ url = obj. URL. match (reg_module_url), ref = bases [0] | scripts [0], name = obj. name; url = _ URL & _ URL [1]? _ URL [1]: This. getbasepath () + "/" + obj. url + ". js "//? Timestamp = "+ 1 * new date; If (! This. requestedurl [url]) {This. requestedurl [url] = 1; var node = Dom. createelement ("script"); node. charset = "UTF-8"; node [name] = Name; node. id = "_" + name + "_"; node. async = true; // If the async attribute is true, the script is executed asynchronously relative to the rest of the document, so that the script can continue to be parsed on the page. Node. onerror = function () {cleartimeout (obj. timeoutid); obj. errback (); Dom. require. removescript (this);} node. onload = node. onreadystatechange = function () {If (-[1,] | reg_readystate.test (this. readystate) {/* the script of opera also has readystate, but if the request address does not exist, it will not enter the */If (node [name]! = Name + "_ loaded") {cleartimeout (obj. timeoutid); obj. errback ();} Dom. require. removescript (this) ;}} node. src = URL; // http://paulirish.com/2011/surefire-dom-element-insertion/ ref. parentnode. insertbefore (node, ref) ;}}, removescript: function (node) {// remove the generated node var parent = node. parentnode if (parent & parent. nodetype = 1) {If (node. clearattributes) {node. clearattributes ();} else {node. onload = node. onreadystatechange = node. onerror = NULL;} parent. removechild (node) }}); // obtain the URL Dom of the core module first. require. getbasepath (); window. DOM = dom?##(this,this.doc ument)

Https://github.com/BorisMoore/DeferJS

Https://bitbucket.org/scott_koon/bootstrap/src/a94d219da3e9/README

Http://jupiterjs.com/news/stealjs-script-manager

Http://bdframework.org/bdLoad/

Https://github.com/unscriptable/curl

Http://www.dustindiaz.com/scriptjs/

Https://github.com/rgrove/lazyload/

Https://github.com/Cerdic/jQl

Http://yepnopejs.com/

Http://labjs.com/

Http://headjs.com/

Http://stevesouders.com/controljs/

Http://requirejs.org/

Https://github.com/chriso/load.js

Http://www.andresvidal.com/jsl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.