andlrc andlrc - 4 months ago 7x
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:

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),


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.