Page MenuHomePhabricator

JavaScriptMinifier: Skip '+' when both side is a literal
Closed, DeclinedPublic

Description

Sometimes a javascript literal has a break to add a manually newline or to break wikisyntax (like signature, the tracking of cats and templates of script pages was changed in 1.19, but many scripts are using that in production), but in that case it is possible for the minifier to skip the quotes and the plus and save three bytes.

For the javascript literal with slash at the end the minifier can change that to a single literal to save two bytes (slash and newline).

"te"+"xt"
=> "text"
"te          /
xt"
=> te          xt"

Only when someone has fun to do it. Thanks.


Version: 1.20.x
Severity: enhancement

Details

Reference
bz34905

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 12:18 AM
bzimport set Reference to bz34905.
bzimport added a subscriber: Unknown Object (MLST).

If you look at libraries like UglifyJS[1], there are a lot of optimizations that can be done without using Google Closure Compiler. That said, we need to be careful because while these optimizations appear to be safe, if there's anywhere on the web we can prove that wrong it's likely to be on Wikipedia with it's abundance of core, extension, site, user and gadget scripts all running together.

[1] https://github.com/mishoo/UglifyJS

I think there's also something to be said for the minifier sticking to minifying and not actually changing javascript code (no matter how redundant it may seem).

(In reply to comment #2)

I think there's also something to be said for the minifier sticking to
minifying and not actually changing javascript code (no matter how redundant it
may seem).

That it right, but bug 31286 is also for minify and must change the javascript a bit. Feel free to make the bugs as WONTFIX or so, if you think, that is not good inside a minifier.

Marking bugs that suggest altering the token stream in JavaScriptMinifier as wontfix.

If we decide to go that way, it is probably best to use existing libraries such as UglifyJS which are much more advanced at this.

We aren't doing that yet because of the performance penalty involved with iterating over the token stream and reformatting it (since we do all of this on-demand on production servers).