JavaScript page rendering Speed test script sharing _javascript tips

Source: Internet
Author: User

Copy Code code as follows:
/* Gets the timestamp of the start of the render, stored in the array page_speed_time.
......

Copy Code code as follows:

......
/* At the end of the page, calculate the time to load the page * *
</body>
<script src= "Http://ossweb-img.qq.com/images/js/pagespeed/page_speed_v2.js" ></script>


Here is an analysis of the contents of the Page_speed_v2.js file. Reformat the script to make it easier to read.

Copy Code code as follows:

/* Execute anonymous function Build Object Pagespeed * *
;(function () {
Pagespeed = {};/* There is no var keyword, which is equivalent to referring to window. Pagespeed *

/**
* Binding Createscript Method
*
* @param the value of the SRC attribute of the String a script label
* @param the value of the id attribute of a String B script label
*/
Pagespeed.createscript = function (A, b) {
var c = null;

if (document.getElementById (b)) {/* The script label already exists * *
c = document.getElementById (b)
} else {/* does not exist, create script label * *
c = document.createelement (' script ');
var d = null;
if (document.getelementsbytagname) {
D = document.getElementsByTagName (' head ') [0] | | Document.documentelement;
} else {
D = document.documentelement;
}
D.insertbefore (c, D.firstchild); /* Call the InsertBefore method to insert the newly created script label as the first child element.
}

* * Here the curly braces play the Code fragment grouping function.
{
C.setattribute (' type ', ' text/html ');
C.setattribute (' style ', ' display:none; ');
C.setattribute (' CharSet ', ' gb2312 ');
C.setattribute (' id ', b);
C.setattribute (' src ', a);
}

return C; /* Return to create a successful script tag element * *
};

/**
* Binding Submitdataforpagespeed Method
*
* @param object A map objects
*/
Pagespeed.submitdataforpagespeed = function (a) {
var B = {
' Name ': ',
' Rate ': 0
};
B.name = A.name;
B.rate = a.rate;

/* A.page_speed_time The last element of the array minus the first element * *
b[' 1 '] = a.page_speed_time[a.page_speed_time.length-1]-a.page_speed_time[0];

for (var i = 1; i < a.page_speed_time.length-1; i++) {
b[(i + 1) + '] = A.page_speed_time[i]-a.page_speed_time[0]
}

* * Submit Speed Test Results script/*
var c = ' http://pagespeed-ied.qq.com/r.cgi ';

/* Iterate through the elements of the B array, building query String * *
var d = [];
For (var p in b) {
D.push (p + ' = ' + b[p])
}
C + + '? ' + d.join (' & ');

/* Create script label Submit speed result
Pagespeed.createscript (c, ' submitforpagespeed ')
};

/**
* Binding Defaultsubmit Method
*
*/
Pagespeed.defaultsubmit = function () {
var a = ';
try {
A = Location.host
catch (e) {}

var B = {
' Name ': A,
' Rate ': 1,
' Page_speed_time ': []
};

if (!b.name) {
Return
}

if (! (typeof (Page_speed_time) = = ' object ' && page_speed_time instanceof Array)) {
Return
}

/* Get a new time stamp/*
Page_speed_time.push (New Date (). GetTime ());

B.page_speed_time = Page_speed_time;

/*
* I don't understand why we need a new variable AAA, can I use a directly?
* Try ... the catch structure is using a new variable AAAA but never used, why? Is it supposed to be AAA?
*/
var aaa = ';
try {
AAAA = Location.host
catch (e) {}

var c = Math.floor (Math.random () * 10000);

if (AAA = "ktv.qq.com" | | | | aaa = "ttd.qq.com" | | | aaa = "tian.qq.com" | | | aaa = "sura.qq.com" | |-AAA = "Gw.tnt.qq.com" | | AAA = "007.qq.com") {
c = Math.floor (Math.random () * 1000);
}

* * Random probability submission Data * *
if (c <= b.rate * 1) {
Pagespeed.submitdataforpagespeed (b);
}
};

/**
* Binding Submit Method (for CDN speed?)
*
* @param String a name
*/
Pagespeed.submit = function (a) {
var B = pagespeed.cdn_page_speed_submitdata;
var c = {};
For (var p in b) {
C[P] = b[p]
}
C.name = A | | C.name;
Pagespeed.submitdataforpagespeed (c);
}
})();

try {
* * 1 seconds to attempt to submit data * *
settimeout (function () {
Pagespeed.defaultsubmit ()
},
1000);
catch (e) {}

/* Last note, the second paragraph is a 32-bit 16-digit number, which should be similar to the ETAG used to mark the content version.
* |xgv00|ca82276cd78ac911d3d4310ba1408236 * *

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.