隨手寫了個小工具,主要為了測試不同混淆程度的javascript腳本的加載速度
1. [代碼]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. [代碼]實際用例 ? ??
<!doctype html>
<html>
<head>
<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() {
?
// 由于為了測試單獨加載某個腳本文件的實際速度,所以該對象的代碼被直接加載寫在頁面中
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>
</head>
<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>
</html>
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
