javascriptページレンダリング速度テストスクリプト共有


/*           ,      PAGE_SPEED_TIME  */
<html><script type="text/javascript">/*tag*/PAGE_SPEED_TIME = [new Date().getTime()];</script><head>
......
</head>

......
/* , */
</body>
<script src="http://ossweb-img.qq.com/images/js/pagespeed/page_speed_v2.js"></script></html>
パジ_を分析します。speed_v 2.jsファイルの内容。このスクリプトを再フォーマットして、読みやすくします。

/* PageSpeed */
;(function() {
    PageSpeed = {};/* var , window.PageSpeed */

 /**
     * createScript
  *
  * @param String a script src
  * @param String b script id
  */
    PageSpeed.createScript = function(a, b) {
        var c = null;

        if (document.getElementById(b)) { /* script */
            c = document.getElementById(b)
        } else { /* , script */
            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); /* insertBefore , script */
        }

  /* */
  {
            c.setAttribute('type', 'text/html');
            c.setAttribute('style', 'display:none;');
            c.setAttribute('charset', 'gb2312');
            c.setAttribute('id', b);
            c.setAttribute('src', a);
        }

        return c; /* script */
    };

 /**
     * submitDataForPageSpeed
  *
  * @param Object a Map
  */
    PageSpeed.submitDataForPageSpeed = function(a) {
        var b = {
            'name': '',
            'rate': 0
        };
        b.name = a.name;
        b.rate = a.rate;

  /* a.PAGE_SPEED_TIME */
        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]
        }

  /* */
        var c = 'http://pagespeed-ied.qq.com/r.cgi';

  /* b , query string */
        var d = [];
        for (var p in b) {
            d.push(p + '=' + b[p])
        }
        c += '?' + d.join('&');

  /* script */
        PageSpeed.createScript(c, 'submitForPageSpeed')
    };

 /**
  * defaultSubmit
  *
  */
    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
        }

  /* */
        PAGE_SPEED_TIME.push(new Date().getTime());

        b.PAGE_SPEED_TIME = PAGE_SPEED_TIME;

  /*
   * aaa, a ?
   * try ... catch aaaa , ? 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);
        }

  /* */
        if (c <= b.rate * 1) {
            PageSpeed.submitDataForPageSpeed(b);
        }
    };

 /**
  * submit ( CDN ?)
  *
  * @param String a
  */
    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 */
    setTimeout(function() {
        PageSpeed.defaultSubmit()
    },
    1000);
} catch(e) {}

/* , 32 16 , ETag */
/*  |xGv00|ca82276cd78ac911d3d4310ba1408236 */