Slimmer with --hardcore

06 May 2006   1 comment   Python

Powered by Fusion×

Last week I wrote about a hope of slimming "private functions in Javascript" but realized that it was futile since it's not really possible. It led me to another idea where I rewrite all long-named functions within the code and relabel them at the end. The idea is that code that looks like this:

function parseSomething(z) {
function foo(x, y) {
    return parseSomething(x) + parseSomething(y);

becomes this:

function _A(z) {
function _B(x, y) {
    return _A(x) + _A(y);
var parseSomething=_A;

None of the functionality is ruined and in this case we save about 10bytes.

It's not a huge save but that's also why it only takes effect if you use the --hardcore parameter. The --hardcore parameter also corrects the parameter variables inside the functions. Allow me to demonstrate:

peterbe@trillian:~ $ python --hardcore --test plone.js 
Took 1.887 seconds
Bytes before: 92739
Bytes after:  47593
Bytes after zlib: 15081
Bytes saved:  45146 (44K)  (51.0% of original size)

peterbe@trillian:~ $ python --test plone.js 
Took 0.467 seconds
Bytes before: 92739
Bytes after:  51088
Bytes after zlib: 15179
Bytes saved:  41651 (40K)  (55.0% of original size)

It's not a huge improvement with these new "hardcore techniques" but it at least works.


Peter, I don't know about the JavaScript, but I bet you'll get a few funny search engine queries for this page :-)
Thank you for posting a comment

Your email will never ever be published

Related posts

Watford kung fu club 04 May 2006
Next: and Instant Domain Search 16 May 2006
Comparing YUI Compressor and slimmer 17 November 2009
slim, a new free web service for white space optimisation 25 July 2006
Private functions in Javascript? 29 April 2006
Smooth anchor scrolling Javascript 17 February 2006
Optimize with 15 February 2005
XHTML, HTML and CSS compressor 07 April 2004