question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thoughts on reducing browser bundle size

See original GitHub issue

In my current app simple-peer is about 10% of an application size and about 20% of JS code size. Specifically, while index.js is 29.5KiB and one might expect that minified version would be even smaller, simplepeer.min.js is whopping 86.5KiB right now.

Before I create and start maintaining a fork of this project, I’d like to know if if this is something that can be fixed upstream.

2 packages that cause this huge size:

  • readable-stream
  • buffer

readable-stream is valuable in Node.js, but not so much in browser environment. Is it possible that future versions of simple-peer will stop using it entirely and replace with something lightweight instead? I imagine it wouldn’t be too hard to implement a wrapper or even offer an optional one with this library.

buffer is a simpler one, once readable-stream is eliminated we’ll just need to switch from Buffer to Uint8Array, which is quite easy to do.

Current bundle size doesn’t seem tolerable to me given that it is just a wrapper around native features, so I hope for your understanding here. If these changes seem reasonable, I’d be happy to implement them myself, otherwise I’ll be forced to create something like simple-peer-light and just maintain that fork forever.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mitschabaudecommented, Jan 5, 2021

Hi, not directly related but starting from @nazar-pc’s work I made a fork of simple-peer which has no external dependencies at all: mitschabaude/simple-peer-light

It’s on npm as well: npm install simple-peer-light. Only works in the browser and does not support the node stream API.

The motivation was to be able to use simple-peer in a Snowpack app, which relies on rollup which doesn’t manage to bundle readable-stream (see https://github.com/nodejs/readable-stream/issues/348). As a nice side-effect I got an 80% size reduction for this lib.

I post this just in case it helps someone like myself. Obviously, in this repo you want to support the stream API and @feross knows the way to go.

Thank you all for this excellent library ❤️

4reactions
nazar-pccommented, Jun 12, 2018

Thanks, makes a lot of sense now. In this case I agree it might be a good idea to wait.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Small Bundles, Fast Pages: What To Do With Too Much ...
The effects of a large bundle can be partially mitigated by caching, compressing and minifying script resources, though reducing the size of ...
Read more >
Reducing JavaScript Bundle Size. Part One
Part One: Measurements and high-level views of strategies. Welcome to part one of a series focused on reducing JavaScript bundle size.
Read more >
Reducing JavaScript bundle size - Medium
We can optimize that by importing only what we use, and Webpack will eliminate all unused code from the bundle. With the named...
Read more >
Why our websites are slow — Importance of bundle size
By relying on browser standards the amount of JS that needs to be sent and parsed by the client is dramatically reduced. Compression...
Read more >
3 ways to reduce webpack bundle size - Jakob Lind
With webpack, you can split your bundle into many smaller bundles, and then the browser can automatically fetch the bundles needed asynchronously. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found