unorm icon indicating copy to clipboard operation
unorm copied to clipboard

Compression on build

Open dead-claudia opened this issue 10 years ago • 2 comments

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:

  1. Stringify the JSON.
  2. Compress it with bzip2 (near the top in both speed and efficiency).
  3. Base64-encode it. This will help remove some redundancy.
  4. Include that as a string in the built source.

And then, on load or first use on the target side:

  1. Decode it.
  2. Decompress it. (should be significantly faster than compression)
  3. Parse the JSON.
  4. Ready to use.

dead-claudia avatar Aug 16 '14 17:08 dead-claudia

Also, a suggestion of a potentially good library: https://github.com/cscott/compressjs

dead-claudia avatar Aug 16 '14 18:08 dead-claudia

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.

phadej avatar Aug 17 '14 11:08 phadej