Javascript minifying

Oct 15, 2010 at 11:55 PM
Edited Oct 15, 2010 at 11:56 PM

I've been playing around with the StripWhitespace function in the JavascriptHandler to try and increase performance on it. What I tried doing was replacing the functionality with the Microsoft Ajax Minifier project instead, found at http://ajaxmin.codeplex.com/.

I ran both StripWhitespace and Minifier in a few loop tests(just 100 iterations) a few times and was pretty surprise by the results!

My test script was one of the WebResource scripts(the one with WebForm_PostBackOptions as the first function). This script is 20.3k uncompressed.

StripWhitespace: Average time was 80ms,  reducing the file size to 15.5k

Minifier only removing whitespace: Average time was 7ms, reducing the file size to 14.5k

Minifier with code minifying(not just whitespace): Average time was 7.3ms, reducing the file size to 10k

 

Is there any reason we're not using the Ajax Minifier over the built in one? It's clearly more performant from my own tests on my laptop. It also offers a ton of settings so it can be tweaked any which way.  I think it may speed up initial start time of the blog, too, because there won't be any need to compile all of the compile-flagged Regex statements.

Coordinator
Oct 17, 2010 at 6:39 AM

I can imagine that the MS Ajax Minifier produces a smaller file ... especially since it renames local variables to 1-letter names.  That's really good that it not only produces a smaller file, but does it about 10 times faster.

Maybe we can include that.  Traditionally, BE has had a rule to not include assemblies.  The only DLL assembly in BE now is the BlogML.dll, but the source code is at least included in the code repository (Mercurial).  It might be more ideal to put the Ajax Minifier source code into the BE core, rather than the DLL itself.  This way we stay consistent with the rule, and having the source code in the BE core would be generally good (although not necessary) for debugging purposes.

Oct 18, 2010 at 10:38 PM

I think the only issue(if it'd even be considered an issue) with adding the Minify source to the BE.Core library is that there's porbably more files in the Minify project than there are in the entire BE.Core library combined. It's a fairly large project.

Coordinator
Oct 19, 2010 at 3:47 AM

Good point, I didn't realize there were so many files.  Well, it might be better than to just include the DLL without the source code files.  And maybe include a link to the source code page somewhere in the BE code (e.g. in the JavaScript Handler file), and if anyone complains about having the DLL without source code, then we can do something about that then!