Faster than jquery's document. Ready Method

Source: Internet
Author: User

This is an article I saw in the blog Park last time. Article It has been tested that it is indeed faster than jquery's $ (document). Ready (function () {...}), and it is no problem in mainstream browsers such as IE and Firefox,

I forgot who the original is. If the master can contact me, I will add the original source immediately. Sorry.

CopyCode The Code is as follows: var jb51 = new function (){
DOM = [];
Dom. isready = false;
Dom. isfunction = function (OBJ ){
Return object. Prototype. tostring. Call (OBJ) = "[object function]";
}
Dom. Ready = function (FN ){
Dom. initready ();
// If the DOM tree is not built, take the second step and store it together.
If (DOM. isfunction (FN )){
If (DOM. isready ){
FN ();
// If the Dom has been built, kill one
} Else {
Dom. Push (FN );
// Store loading events
}
}
}
Dom. fireready = function (){
If (DOM. isready) return;
Dom. isready = true;
For (VAR I = 0, n = Dom. length; I <n; I ++ ){
VaR fn = Dom [I];
FN ();
}
Dom. Length = 0;
// Clear the event
}
Dom. initready = function (){
If (document. addeventlistener ){
Document. addeventlistener ("domcontentloaded ",
Function (){
Document. removeeventlistener ("domcontentloaded", arguments. callee, false );
// Clear the load function
Dom. fireready ();
},
False );
} Else {
If (document. getelementbyid ){
Document. Write ("<SCRIPT id = \" ie-domready \ "Defer = 'defer' src = \" //: \ "> <\/SCRIPT> ");
Document. getelementbyid ("ie-domready"). onreadystatechange = function (){
If (this. readystate = "complete "){
Dom. fireready ();
This. onreadystatechange = NULL;
This. parentnode. removechild (this)
}
};
}
}
}
}

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.