thebarty / analytics-js-without-segment

A toolset to use Segments open-source analytics library (analytics.js) WITHOUT using the paid Segment service (segment.com). To be used with your favorite analytics-tools like Google Analytics, Mixpanel, Hotjar, etc.
48 stars 8 forks source link

Why include terser? #2

Open estrattonbailey opened 5 years ago

estrattonbailey commented 5 years ago

Hey there, thanks for the lib and the original blog post. Seams like a pretty solid option!

However, I'm curious why you chose to include terser to minify the snippet code. It adds considerable weight to the overall payload of this library, and looks like it could easily do without.

advance512 commented 5 years ago

@estrattonbailey Can you offer some data to back this up? How much weight does it add to the payload?

estrattonbailey commented 5 years ago

@advance512 according to Bundlephobia, 82.9% of its 364.4kb (minified) payload is Terser.

advance512 commented 5 years ago

@Henning @thebarty Any thoughts on this? Can we not include terser?

henning commented 5 years ago

No idea. Do what you like @advance512

estrattonbailey commented 5 years ago

I'm fairly positive that this library doesn't need a AST parser embedded inside it :P

I don't actually have a need for this anymore, so I'm gonna duck out ✌️ good luck y'all.

advance512 commented 5 years ago

@estrattonbailey Mind sharing what you ended up doing instead?

iggyvanlith commented 5 years ago

For anybody else looking for a solution for this: What I did is to write a simple Node script that outputs the generated javascript file and runs before your build. The renderAnalytics function is perfect for this. It's basically just executing that function and then writing it to a file. Put it in a gist: https://gist.github.com/iggyvanlith/167b2d196c20a6abb71ea0f7482020a0

Saved some 100's of kb's from my application.

imjared commented 5 years ago

Ran a bundle analyzer this morning and Terser is by far the biggest part of our clientside build. Seems to totally defeat the point of minification/obfuscation of the analytics snippet since it adds 94kb (gzipped!) in the name of saving what's probably a few bytes.

I'm pretty swamped at the moment but would consider sending a PR to remove if it's open for consideration.

image

thebarty commented 5 years ago

PRs are very welcome!

Let's make this package better and better together