Bug 987487 - [Gaia] [Build] Refactoring webapp-optimize.js and unit tests

https://bugzilla.mozilla.org/show_bug.cgi?id=987487
To land this already big enough patch, I would prefer to keep this for another revision.
Also we need to prove the value of this before adding such optimization.