[Json-rpc-java] jsonrpc.js and Dojo shrinksafe

Arthur Blake arthur.blake at gmail.com
Tue Jul 31 05:16:32 SGT 2007


Anyone who works with web 2.0 and JavaScript a lot has probably encountered
these tools:

The JavaScript minifier (JSMin)
http://www.crockford.com/javascript/jsmin.html
Dojo Shrinksafe  http://dojotoolkit.org/docs/shrinksafe

These are tools for stripping the puffed air (whitespace and comments) out
of JavaScript code so that it can be optimized for smaller download sizes.
Dojo Shrinksafe goes a little further than JSMin in that it parses the
JavaScript and shrinks down local variable names too.

I use both tools.  But the stock jsonrpc.js doesn't compress properly with
Dojo Shrinksafe.
For some reason, the redundant function definitions confuses it.
I'm not sure why these redundant function definitions are there in the first
place, but when I remove them, it shrinks properly.

For example,
I changed:

toJSON = function toJSON(o)

to just

function toJSON(o)

and

JSONRpcClient.Exception =
function JSONRpcClient_Exception_ctor(code, message, javaStack)

to just

JSONRpcClient.Exception = function (code, message, javaStack)

All the functions are defined redundantly this way, and I fixed them all in
my copy of jsonrpc.js.  I've been running this way for quite some time, and
I haven't encountered any errors as a result of running this way.
I can't think of any good reason why these redundant function definitions
are there in the first place... and when I remove them, Dojo Shrinksafe
properly shrinks the file.
I'd like to commit these changes if everyone agrees this is a good idea...

Arthur Blake

P.S. There are more problems that I have found with jsonrpc.js, and I will
address them one issue at a time in upcoming emails.


More information about the Json-rpc-java mailing list