views:

1546

answers:

2

I just found Dean Edwards javascript packer here: http://dean.edwards.name/packer/

It has a couple of options,

  1. Base62 encode
  2. Shrink variables

To test it I took the latest version of jquery that is already minified to 56kb and ran it on that page above with shrink variables, the result is the same size file, 56kb.

I then ran the original file again with both Base62 encode and Shrink variables selected and the result was a 42kb file.

Now I don't know a lot about minifying and packing other then it makes the filesize smaller. But I am curious as to what Base62 encode is doing, is it bad to use it? I see it makes the file much smaller but does it create more work/load later on to decode it on the page?

+1  A: 

It does create more work on the client. The client has to run the code to unencode the encoded script. This is pretty obvious if you enter just a little bit of code in the encoding block.

For example:

var a = 10;

Encodes as:

eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0 1=2;',3,3,'var|a|10'.split('|'),0,{}))
tvanfosson
+5  A: 

Base 62 is nothing but a positional notation. That is, it can be used to represent very long normal text by a very shorter version.

Using Base62 adds an extra step before the js can be put to use by clients. For jQuery kind of library this step may take an extra 100ms to 500ms of time on clients, depending on many factors.

Now we can compare the reduction in time to download the script to extra time taken to execute the script. It may reduce download time by 50ms but takes an extra 100ms to process it. Diminishing returns!!

Arpit Tambi
good points, thanks, maybe I should stay away from it
jasondavis