-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add optional navigator.sendBeacon transport #240
Conversation
var transport = options['transport']; | ||
if (transport) { | ||
options.transport = transport; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just realized you probably need this to avoid the minifier messing with 'sendBeacon'
; disregard my comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: