andlrc andlrc - 5 months ago 17
Javascript Question

Why does Google Analytics minify to: `1*new Date()`?

Why is Google Analytics tracking minified to:

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;


Any reason not to use the later versions?

Full code:

(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');

Answer

No, no reason at all. In fact, Google Analytics recommends version #3 in their alternative async tracking snippet.

The most likely answer to your question is that a human being was responsible for writing the original snippet, and a human being didn't quite get the 100% most optimal minified version of it. In fact, you can also leave out the a.async=1 part too because all dynamically injected script are async by default.

If you want to change it to save 3 bytes, go ahead. No browsers in use today will fail on your #3 syntax.