mozilla-b2g/gaia — pull request #15430 by jrburke (2014-01-16 22:19:25+00:00)
Title: Bug 960343 - email: minify JS

This pull request turns on uglify2 minification for email, and it contains a bypass Makefile variable, GAIA_EMAIL_MINIFY=none, that can be used in dev to skip uglification, since it can take a bit of time.

The Makefile also limits what it copies out of the /shared directory to avoid uglify2 complaining about some of the files, and to reduce the amount of work.

Here are the application.zip file size comparisons, with different uglify options:

* beautify: keep line returns and indentation
* compress: tries to optimize some code constructions
* mangle: change variables/identifiers to shorter names

Sizes in bytes:

1) 977,680 - no minification
2) 630,064 - beautify no mangle no compress (just remove comments basically)
3) 573,836 - compress, mangle, with beautify on
4) 537,023 - compress, mangle, no beautify (just long lines of JS)

I chose setting 3, so that line breaks are preserved. This gives a good savings on file size while also allowing us to get error messages with a usable line number. However, since uglify2 is modifying the code, if we ever run into trouble with that, where it introduces an error, we may fall back to setting 2, which just removes code comments.

Looking at the application.zip contents, we are pretty aggressive with unnecessary file stripping. There are a couple of things we could still do:

1) trim the .html files from the shared/style and shared/style_unstable. These just seem to be demo pages for the CSS. I did a quick manual removal and this seemed to save about 40-50KB in zip size. As this affects all gaia apps, the bulk savings may be add up, so I will file a separate bug, hopefully with a patch, later today for this.

2) trim some .html files that are inlined in the JS for email. Doing a quick hack, this might reduce the zip size by about 8KB. So I do not think it is worth pursuing this one at this time.