tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.11k stars 316 forks source link

Decrease browser bundle size #679

Open mb21 opened 7 months ago

mb21 commented 7 months ago

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?

Acconut commented 6 months ago

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.