zip binaries
-
I read about shrinking the wasm file with gzip. With zip/gzip/rar the file is indeed considerably smaller. I don't understand how to implement that in my project. I assume I need to download the compressed file and decompress it locally with qtloader.js? Does anyone have experience with that and does it minimize the waiting time? And of course an example is appreciated.
-
@Jan-Bakker The compression is done in the webserver, like apache. I recommend brotli compression as that is superior to gzip.
-
@Jan-Bakker said in zip binaries traffic Jam 3D:
I read about shrinking the wasm file with gzip. With zip/gzip/rar the file is indeed considerably smaller. I don't understand how to implement that in my project. I assume I need to download the compressed file and decompress it locally with qtloader.js? Does anyone have experience with that and does it minimize the waiting time? And of course an example is appreciated.
Yes, compressing your WASM file with gzip can significantly reduce its size and improve loading times. Example of how to load and decompress a compressed WASM file with pako:
import pako from 'pako'; fetch('my-wasm-file.wasm.gz') .then(response => response.arrayBuffer()) .then(buffer => { const decompressedData = pako.inflate(new Uint8Array(buffer)); const wasmModule = new WebAssembly.Module(decompressedData); const wasmInstance = new WebAssembly.Instance(wasmModule); // Use wasmInstance here });
This code will load the compressed WASM file 'my-wasm-file.wasm.gz', decompress it using pako, and then instantiate the WASM module. Once the module is instantiated, you can access its exported functions and properties using wasmInstance.
Compressing and decompressing the WASM file will add some overhead to the loading process, but it will still be faster than loading the uncompressed file, especially for larger WASM files. The exact difference in loading time will depend on the size of the WASM file and the performance of your browser.
-
Do not manually compress these files; you can leave it to Nginx to handle automatically. After adding these configurations to my Nginx conf file, automatic compression is enabled:
gzip on; gzip_min_length 32k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain text/css text/xml application/xml application/json text/javascript application/javascript application/octet-stream;
You can visit this address to see the compression effect. Open the F12 console in Chrome, and you will notice that the wasm file has been compressed.
https://web.jasonserver.com:10035/JQClock/JQClock.html