What’s the best way to include binary data in a small JavaScript file?

0
0
Asked By CuriousCoder42 On

I'm looking to keep my JavaScript file size to a minimum while needing to embed some binary data. Is there a method that's more efficient than base64 for storing this data inline? Ideally, I'd like to find a way to store it byte-for-byte without bloating my file too much.

2 Answers

Answered By DataDynamo77 On

Another approach is to implement a compression layer on top of your data. You could use something like base64 (or an ArrayBuffer), then compress that data using a method like zipping or run-length encoding (RLE). Just keep in mind you need to figure out if the space gained from compression outweighs any additional overhead it introduces!

Answered By BinaryWhiz88 On

Have you thought about using an ArrayBuffer? It's a good option for working with binary data directly in JS.

CuriousCoder42 -

I actually want it to be part of a locally opened HTML page, so keeping everything in one file would be ideal!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.