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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post 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?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
Post Reply