Skip to content

Conversation

@zalo
Copy link
Contributor

@zalo zalo commented May 8, 2025

I'm a big fan of the Code Generator tool, but I noticed the all-in-one pages serialize the game as a JSON array, which can get kind of chunky.

This PR swaps the JSON for a base64 string, bringing a 53.35mb .html down to 21.85mb. This should help with storage and load-times.

Zipping the .html afterwards brings the whole thing down to within 10% of the original game size, which is nice if your static file server supports archiving like this.

bytes <-> base64 conversions adopted from examples on this page: https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa

I'm a big fan of the Code Generator tool, but I noticed the all-in-one pages serialize the game as a JSON array, which can get kind of chunky.

This PR swaps the JSON for a base64 string, bringing a `53.35mb` .html down to `21.85mb`.   This should help with storage and load-times.

Zipping the .html afterwards brings the whole thing down to within 10% of the original game size.

bytes <-> base64 conversions adopted from examples on this page: https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
@netlify
Copy link

netlify bot commented May 8, 2025

Deploy Preview for emulatorjs-org ready!

Name Link
🔨 Latest commit 0965e29
🔍 Latest deploy log https://app.netlify.com/sites/emulatorjs-org/deploys/681d24f3df2f7d0008da2c45
😎 Deploy Preview https://deploy-preview-58--emulatorjs-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@zalo
Copy link
Contributor Author

zalo commented May 8, 2025

Hmm, I notice the .zip files this tool outputs are getting a 0% compression ratio... perhaps we can do better...

@zalo
Copy link
Contributor Author

zalo commented May 8, 2025

Hmmm, I can add a bit of compression before applying the base64 encoding (Final .html size goes from 21.85mb -> 16.32mb; which pretty much matches the size of the original game), but it will add some conceptual messiness to avoid more libraries, so I'll make it a different PR.

zalo added a commit to zalo/emulatorjs.org that referenced this pull request May 8, 2025
This PR adds compression to the generated .html files using the browser's built-in gzip compression/decompression routines.

This brings what would have been a `53.35mb` .html on master (or a `21.85mb` .html with EmulatorJS#58 ) down to `16.32mb`.   This further compresses down to `12mb` if zipped.

Due to the async call needed for this, I made this a separate PR since the structure of the generated .html has changed to only load the emulator after the game data has been decompressed.   This is incompatible with the non-single-file-packing code, so it has been removed.
Copy link
Member

@ethanaobrien ethanaobrien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks

Copy link
Member

@allancoding allancoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works in my tests. Nice!

@ethanaobrien ethanaobrien merged commit 2ba6f85 into EmulatorJS:main May 9, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants