fireproof-storage / fireproof

Realtime database, runs anywhere. Install Fireproof in your front-end app or edge function, and sync data via any backend.
https://fireproof.storage
Other
220 stars 16 forks source link

make browser bundle lighter by using web crypto #1

Closed jchris closed 9 months ago

jchris commented 10 months ago

The current esbuild system is in scripts/settings.js. It works but it bundles a bunch of crypto we don't need. Check out getDefaultRandom() here

There is currently an unused scripts/rollup.js configuration waiting for someone to polyfill Buffer. It's targetted by npm run build:rollup and ready for you to hack around on.

Here's what my acceptance process looks like. Any help optimizing that would be rad too.

Screen Shot 2023-08-18 at 8 11 52 AM

If all you do is try different builds and leave notes here, that's useful too.

jchris commented 10 months ago

The biggest next step is to try a build that uses browser crypto instead and see how far we get:

https://github.com/fireproof-storage/fireproof/blob/main/packages/fireproof/src/encrypted-block.ts#L2C13-L2C13

jchris commented 10 months ago

I think testing without included crypto in the bundle can be done by changing the require and building and testing. Assuming browsers work great we can then see how light it is and make the IIFE build that light.

I think we only need the heavy crypto in the node build https://github.com/fireproof-storage/fireproof/blob/main/packages/fireproof/scripts/settings.js#L93

jchris commented 10 months ago

we should probably enable the optional banners during this testing it makes it easier to track what's happening https://github.com/fireproof-storage/fireproof/blob/main/packages/fireproof/scripts/settings.js#L33

jchris commented 9 months ago

got it down to 500kb with #15 -- that's about 10x smaller