unorm
unorm copied to clipboard
Compression on build
The udata
variable obviously has size issues, already pointed out in #17, but I was thinking that pre-compressing it in the build phase would be able to significantly cut it down in size. For example, using the following process to compress that variable's content:
- Stringify the JSON.
- Compress it with bzip2 (near the top in both speed and efficiency).
- Base64-encode it. This will help remove some redundancy.
- Include that as a string in the built source.
And then, on load or first use on the target side:
- Decode it.
- Decompress it. (should be significantly faster than compression)
- Parse the JSON.
- Ready to use.
Also, a suggestion of a potentially good library: https://github.com/cscott/compressjs
TL:DR if you worry about wire-transfer size, use gzip compression. This kind of size optimisation is job of build tool, not library maintainers.
The udata
is big, but is very compressable (minimsation in between helps only marginally):
% ll lib
-rw-r--r-- 1 phadej staff 141692 Aug 17 14:31 unorm.js
-rw-r--r-- 1 phadej staff 38186 Aug 17 14:33 unorm.js.gz
-rw-r--r-- 1 phadej staff 34046 Aug 17 14:35 unorm.js.bz2
-rw-r--r-- 1 phadej staff 21832 Aug 17 14:42 unorm.js.xz
-rw-r--r-- 1 phadej staff 136811 Aug 17 14:33 unorm.min.js
-rw-r--r-- 1 phadej staff 36773 Aug 17 14:33 unorm.min.js.gz
bzip2 does compress is better than gzip, but not that much. I'd use xz. Though for all javascripts. not only one part of single of them.