为什么Google Analytics会缩小为:1 * new Date()`?

时间:2015-10-21 19:36:46

标签: javascript google-analytics minify

为什么Google Analytics跟踪会缩小为:

i[r].l=1*new Date();
// instead of: which saves one byte
i[r].l=+new Date();
// or even: which saves 3 bytes
i[r].l=+new Date;

有什么理由不使用更高版本?

完整代码:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

1 个答案:

答案 0 :(得分:3)

不,没有理由。事实上,Google Analytics会在alternative async tracking snippet中推荐第3版。

你问题的最可能的答案是,一个人负责编写原始片段,而人类并没有完全获得100%最优化的缩小版本。实际上,您也可以省略a.async=1部分,因为默认情况下所有动态注入的脚本都是异步的。

如果要更改它以保存3个字节,请继续。今天使用的浏览器不会因#3语法而失败。