Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split long polyfills into multiple files #86

Closed
imranbarbhuiya opened this issue Aug 25, 2023 · 2 comments
Closed

Split long polyfills into multiple files #86

imranbarbhuiya opened this issue Aug 25, 2023 · 2 comments

Comments

@imranbarbhuiya
Copy link
Contributor

imranbarbhuiya commented Aug 25, 2023

Hi, thanks for maintaining this excellent lib. I have an esbuild plugin that uses this lib. In GoogleChrome/lighthouse#15405, it was used to replace the existing unmaintained plugin. But since zlib is a huge package and they are using only gzip fn, they want to exclude the pako/lib/zlib/inflate.js file. Since esbuild doesn't remove unused exports so this is done by changing the contant of this file. And since jspm bundles everything in 1 file, we can't apply same hack with my plugin. Is it possible to split long polyfills into multiple files?

Alternative

Add all the deps as main dependencies instead of dev deps and add src-browser exports in package.json so we can use them directly

@guybedford
Copy link
Member

Hi @imranbarbhuiya thanks for sharing the idea here. If we could dynamically load compression libraries that would definitely be much better for browser load performance. Unfortunately because the compression libraries are all sync, there's no way to use a dynamic import() to defer that load, only on the async paths if we could disable the sync compression stuff. Eg if we could split the library into zlib/promises and zlib separately, then zlib/promises could defer loading of the individual compression libraries using this technique. Unfortunately that is not how Node.js works though!

Short of that the best option would be to use an env var and optimize out code you know won't be needed. If that would help I'd be happy to add one, but it wouldn't be a feature JSPM itself would take advantage of.

@imranbarbhuiya
Copy link
Contributor Author

I don't think env var will be a good solution for all these packages. Maybe esbuild should fix the tree shake issues instead. And I don't think modifying jspm public API for only 1 package is worth it so I'll try if there's any other way to do it without changing jspm API for my usecase only. Thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants