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
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!
Have you thought about using an ArrayBuffer? It's a good option for working with binary data directly in JS.
I actually want it to be part of a locally opened HTML page, so keeping everything in one file would be ideal!