[wp-hackers] Packing JavaScript

Kevin Newman CaptainN2003 at yahoo.com
Wed Sep 19 18:27:16 GMT 2007

Otto wrote:
> +1 to using a wrapper script to gzip the js's.
> +1 to add better header control to that, to increase cache time to
> longer periods.
Cool. If I get around to it, I may take a stab at a plugin that does that.
> -1 to concatenating all the scripts together. This eliminates the
> benefit of caching and also makes the variable header code less
> effective at caching of the normal pages, since script enqueues may be
> variable. Also it introduces problems with how to make an effective
> naming scheme for the concat'ed js's.
I'm not sure that coming up with a naming scheme is that big a problem.
Something like:


Or even use the files last modified date: jQuery=5-5-2007 etc, in case
something changes.

There would be an issue with what to do on the client side if a
particular lib is only used on one page. For example, on my blog I was
using a plugin that relied on Prototype for a while that was used on
every page, and a contact form plugin that relies on jQuery. So on the
contact page I'd have ended up sending a separate copy of the
Prototype.js files, that was included with jQuery. In this case, it
would be more efficient to not combine the two files.

So basically in order to make a concatenating system make sense, there
would need to be a way to add libraries to a site wide queue that is
separate from the single request queue (the way that hook works now) -
maybe there aught to also be separate way to queue up admin wide, and
public wide packages as well (since there are probably usually more libs
used in the admin than in the regular site).

I guess the question is, is it worth all that effort just to slight
reduce the number of connections for js libs (there honestly aren't
_that_ many of them).

Anyway, gzipping the javascript, and adding some better expiry is a good
place to start. The same could be done for css files (is there a queue
function for css?).

Kevin N.

More information about the wp-hackers mailing list