Removed unused functions and rewrote others using modern browser capabilities #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mixpanel-js
is big.The approach I'm taking here is to use modern browsers capabilities to decrease the code size, but a bigger win might come from splitting the lib up into other smaller libs that each can attend a specific use case/feature.
Ex: one for notifications, another for user tracking, etc.
This discussion started at #128
_.identity
-> removed, unused_.timestamp
-> removed, unused_.JSONEncode
->JSON.stringify
_.JSONDecode
->JSON.parse
_.trim
-> replaced withString.prototype.trim
http://kangax.github.io/compat-table/es5/#test-String_properties_and_methods_String.prototype.trim_a_href=_https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim_title=_MDN_documentation_img_src=_../mdn.png_alt=_MDN_(Mozilla_Development_Network)_logo_width=_15_height=_13_/_/a_nbsp;
_.bind
-> replaced withFunction.prototype.bind
http://kangax.github.io/compat-table/es5/#test-Function.prototype.bind
*
_.utf8Encode
-> became much smaller, based on http://ecmanaut.blogspot.ca/2006/07/encoding-decoding-utf8-in-javascript.html_.base64Encode
-> became much smaller usingbtoa
, and it was the only function usingutf8Encode
, so I inlined it there.http://caniuse.com/#feat=atob-btoa
NOTE:
btoa
is not support on IE9 and before, is this a problem?_.dom_query
-> replaced by a much smaller version usingquerySelectorAll
http://caniuse.com/#feat=queryselector
NOTE:
querySelectorAll
is well supported only by IE9+, is this a problem?Numbers:
mixpanel.min.js
: 59.4K -> 52K (-7.4K, 13.5% reduction) (non-gzipped)Please let me know if there is more unused code or if there is anything else I can improve further.