add optional navigator.sendBeacon transport#240
Conversation
| var transport = options['transport']; | ||
| if (transport) { | ||
| options.transport = transport; | ||
| } |
There was a problem hiding this comment.
I'm confused by this, missing how it modifies options. Can you add a clarifying comment if it's intentional?
There was a problem hiding this comment.
Will do - it's because track() is a public API and so "transport" shouldn't be minified, whereas _send_request() is internal and so its options.transport can be minified however closure compiler wants.
There was a problem hiding this comment.
that makes a strange amount of sense, thanks for the explanation
| var sendBeacon = navigator['sendBeacon']; | ||
| if (sendBeacon) { | ||
| sendBeacon = _.bind(sendBeacon, navigator); | ||
| } |
There was a problem hiding this comment.
I'd personally find the code below more readable if I saw navigator.sendBeacon, provides more context even though it's more verbose and you wouldn't need this bind iiuc. Nbd if you prefer it this way.
There was a problem hiding this comment.
just realized you probably need this to avoid the minifier messing with 'sendBeacon'; disregard my comment
There was a problem hiding this comment.
Another size optimization, like we do throughout this SDK. It lets closure compiler compress this down by referring to a minified var rather than injecting "navigator.sendBeacon" every time it's used. The minified version of this code is:
U=I.sendBeacon;U&&(U=c.bind(U,I));so the code below can just refer to U
fixes #184
Several ways to use it: