tus/tus-js-client

Decrease browser bundle size

mb21 opened this issue · 1 comments

mb21 commented

Looking at the bundle files for lib.esm for example:

image

(this was generated in an Astro.js project with rollup-plugin-visualizer).

I was especially curious why lib.esm/browser/fileReader.js is so big even though the source file is only a few lines. Running yarn run build-transpile-esm results in a 14kb file. The problem is that babel includes all the following functions:

_typeof
_regeneratorRuntim
asyncGeneratorStep
_asyncToGenerator
_classCallCheck
_defineProperties
_createClass
_toPropertyKey
_toPrimitive

Most of which is not needed for more or less modern browsers anymore.

I'm not an expert in babel and npm package bundling, but AFAIK it's nowadays best practice for a JS library to kinda just ship the source, so that the bundler in the project that consumes the library can optimize for the browsers they want to support and tree-shake away the functions not used?

Thank you for looking into this!

I'm not an expert in babel and npm package bundling, but AFAIK it's nowadays best practice for a JS library to kinda just ship the source, so that the bundler in the project that consumes the library can optimize for the browsers they want to support and tree-shake away the functions not used?

I agree, we should get rid of the polyfill for async/await and generators. We can assume support for those features in the tooling by now.