analytics-js-without-segment icon indicating copy to clipboard operation
analytics-js-without-segment copied to clipboard

Why include terser?

Open estrattonbailey opened this issue 6 years ago • 9 comments

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.

estrattonbailey avatar Jan 24 '19 19:01 estrattonbailey

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

advance512 avatar Jun 02 '19 11:06 advance512

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

estrattonbailey avatar Jun 02 '19 17:06 estrattonbailey

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

advance512 avatar Jun 03 '19 13:06 advance512

No idea. Do what you like @advance512

henning avatar Jun 03 '19 13:06 henning

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.

estrattonbailey avatar Jun 03 '19 13:06 estrattonbailey

@estrattonbailey Mind sharing what you ended up doing instead?

advance512 avatar Jun 03 '19 17:06 advance512

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.

iggyvanlith avatar Aug 02 '19 13:08 iggyvanlith

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

imjared avatar Sep 04 '19 14:09 imjared

PRs are very welcome!

Let's make this package better and better together

thebarty avatar Sep 05 '19 05:09 thebarty