mixpanel-js
mixpanel-js copied to clipboard
Removed unused functions and rewrote others using modern browser capabilities
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 https://github.com/mixpanel/mixpanel-js/issues/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.
@jbwyme any change this will could be merged? I just wanted to start a conversation. What are the browsers this library has to support?
@tdumitrescu @jbwyme any update on this?
+1 any news?
Let me know if you're moving forward with this, I can solve conflicts to get it merged, but since I didn't get an answer from the beginning I'm not going to do these changes now before I get a clear confirmation.
Let me know if you're moving forward with this, I can solve conflicts to get it merged, but since I didn't get an answer from the beginning I'm not going to do these changes now before I get a clear confirmation.