mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

Removed unused functions and rewrote others using modern browser capabilities

Open fabiomcosta opened this issue 7 years ago • 5 comments

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 with String.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 with Function.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 using btoa, and it was the only function using utf8Encode, 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 using querySelectorAll
 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.

fabiomcosta avatar Sep 21 '17 05:09 fabiomcosta

@jbwyme any change this will could be merged? I just wanted to start a conversation. What are the browsers this library has to support?

fabiomcosta avatar Sep 27 '17 22:09 fabiomcosta

@tdumitrescu @jbwyme any update on this?

ghost avatar Oct 06 '17 12:10 ghost

+1 any news?

hackuun avatar Feb 04 '18 22:02 hackuun

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.

fabiomcosta avatar Apr 05 '18 19:04 fabiomcosta

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.

fabiomcosta avatar Sep 20 '18 05:09 fabiomcosta