Page 1 of 1

How was jQuery compressed? Can we do that for Prototype?

Posted: Fri May 04, 2007 3:09 am
by JAB Creations
jQuery is compressed down to 20KB, which is a reasonable five seconds of load time on dialup. How was jQuery compressed and how can we compress Prototype?

Posted: Fri May 04, 2007 3:51 am
by volka

Posted: Fri May 04, 2007 3:51 am
by JAB Creations
I saw someone released a copy of Prototype and Script.aculo.us using a command line program called jscompact. Is there something windows based that emulates this exact same behavior?

Posted: Fri May 04, 2007 3:55 am
by JAB Creations

Posted: Fri May 04, 2007 7:15 am
by volka
It's the same script.
http://dev.jquery.com/browser/trunk/jquery/build/js/Packer.js wrote: Packer version 3.0 (beta 5) - copyright 2004-2007, Dean Edwards

Posted: Fri May 04, 2007 2:22 pm
by Kieran Huggins
I have a feeling prototype IS compressed - most libraries are available in 2 flavours: compressed and readable. They're functionally identical, but the "readable" prototype is there for code discovery. I would always use the compressed version in a production environment.

Oh, and Dean Edwards is The Man.

Posted: Fri May 04, 2007 4:22 pm
by AKA Panama Jack
Or you can compress on the fly instead of relying on a javascript decompression.

http://dgrin.com/showthread.php?t=22928

And I bet gzip level 9 will compress many times better than the javascript decompression being used above. And it should be many times faster decompressing client side.

Posted: Fri May 04, 2007 7:29 pm
by Kieran Huggins
mod_gzip does this, does it not? If you add a header with php (or mod_rewrite?), you can store the files in their gzipped state on the server, thus saving the continual "zipping".

But really: meh. It should be cached on the client side anyway, let mod_gzip do it's thing and be done with it.

Posted: Fri May 04, 2007 8:16 pm
by AKA Panama Jack
Yes, servers can be setup to automatically gzip everything going out. The PHP software doesn't have to do anything as it is handled by Apache. This means even javascript, css and any other file that is loaded by the page will be compressed on the fly. No need to precompress anything. If you add in support for gzip compression on the output from your PHP program you need to check to see if Apache has the automatic gzip disabled. Do this by checking get_cfg_var('zlib.output_compression'). If it is set to false then you can gzip your output in PHP. If it is set to true then DON'T gzip your PHP output. If you do you will double compress and browsers can't handle that. :)

The thing is many hosts have the library installed so PHP can use it but the servers do not have it enabled through Apache so all output is compressed. So you would have to use something similar to what I linked to to compress your CSS and javascript files on the fly.