A handy gadget was written to test the loading speed of JavaScript scripts with different levels of confusion
1. [Code]timestamp.js
(function () {
if (typeof this. Timestamp = = ' undefined ') {
/**
* Global Timestamp Manager
* @author Janpoem
* Created at 2011.03.30
*/
This. Timestamp = (function () {
var pool = {
' Page_Init ': New Date ()
};
return {
Add:function (flag) {
Pool[flag] = new Date ();
},
Get:function (flag) {
Return typeof flag = = ' undefined '? Pool: (Pool[flag]? Pool[flag]: Pool);
},
Diff:function (To, diff) {
if (!diff)
diff = to, to = ' Page_Init ';
Return (Pool[to] && Pool[diff])? Pool[diff]-pool[to]: 0;
}
}
}) ();
}
}) ();
2. [Code] actual use case?
<!doctype html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>mootools Test page</title>http://www.huiyi8.com/donghua/?
<script type= "Text/javascript" >flash
(function () {
Because the actual speed at which a script file is loaded separately, the code for that object is loaded directly on the page
if (typeof this. Timestamp = = ' undefined ') {
/**
* Global Timestamp Manager
* @author Janpoem
* Created at 2011.03.30
*/
This. Timestamp = (function () {
var pool = {
' Page_Init ': New Date ()
};
return {
Add:function (flag) {
Pool[flag] = new Date ();
},
Get:function (flag) {
Return typeof flag = = ' undefined '? Pool: (Pool[flag]? Pool[flag]: Pool);
},
Diff:function (To, diff) {
if (!diff)
diff = to, to = ' Page_Init ';
Return (Pool[to] && Pool[diff])? Pool[diff]-pool[to]: 0;
}
}
}) ();
}
}) ();
</script>
<script type= "Text/javascript" src= "All.js" onload= "Timestamp.add (' load_complate ');" ></script>
<script type= "Text/javascript" >
Timestamp.add (' process_here#1 ');
</script>
<body>
<div id= "Mt_test" ></div>
<script type= "Text/javascript" >
Console.log (
Timestamp.diff (' load_complate '),//Download a script file speed
Timestamp.diff (' process_here#1 '),//HTML parse process here
Timestamp.diff (' load_complate ', ' process_here#1 ')
);
</script>
</body>