[wp-hackers] compression and caching

Otto otto at ottodestruct.com
Tue Dec 29 15:02:20 UTC 2009


On Mon, Dec 28, 2009 at 10:49 PM, Weston Ruter <westonruter at gmail.com> wrote:
>   2. Minifies code using Google's Closure Compiler.

The existing JS and CSS libraries in the core already are pre-minified
versions of themselves, and those get loaded by default, unless you
force it into debug mode. If you want to include pre-minified versions
of your own personal JS libraries, then that's real easy to do right
now, no third-party servers needed.

>   3. Caches the concatenated/minified code and rebuilds it only when one of
>   its source scripts expires or changes. The optimizescripts_expires filter
>   is provided which allows the far-future expires time to be forced.
>   4. Filename for concatenated/minified script is the md5 of all the
>   handles concatenated together (thus if an additional handle is provided, a
>   new concatenated script is generated).

All this seems like it would offer zero performance improvement to me,
especially on the front end of the site. You're doing all this
processing to save yourself a minor amount of time, when all you
really need to do is to do it manually one time and put the files in
the proper places. Serving static files is *always* faster than
serving dynamic ones. And if you're screwing with the headers, then
you're reaching. You should configure your webserver properly to serve
the proper headers with your static files instead.

Using PHP to overcome your inability or unwillingness to properly
configure your Apache instance is definitely something that should not
be in WordPress.

>   5. Provides a filter to limit which scripts get concatenated (i.e. jQuery
>   on ajax.googleapis.com should be left alone); by default, all scripts on
>   local host are concatenated, and remote scripts are left alone.
>   6. Removes the default 'ver' query parameter which WordPress adds to
>   every script src if no version argument is supplied on
>   wp_enqueue/register_script: this is important for Web-wide caching of
>   scripts loaded from ajax.googleapis.com, for example. When registering
>   new scripts, pass the filemtime in as the version so that whenever a file
>   changes, the concatenated script will be regenerated.

Already done.

http://wordpress.org/extend/plugins/use-google-libraries/

No version parameter gets added, the plugin replaces the existing
enqueued scripts with the google versions. Works perfectly.

>   7. Script optimization can be delegated to a scheduled cron job so that
>   the server does not periodically respond slowly to visitors.

Do your scripts and CSS *really* change often enough that you need to
do this more than one time? I mean, most people are not editing and
adding javascripts and CSS to their site particularly often.

> I'm eager to hear what you all think about this approach and if would be
> good to include in WordPress core so that it can be fast by default in how
> it serves scripts.

There is such a thing as over-optimization. I think that this will
decrease performance on most people's systems, because you're doing a
lot of unnecessary compressing, concatenating, minifying, etc.

That said, for the admin side of things, WordPress *already*
concatenates and minifies both JS and CSS in WP 2.9. In my own
informal testing, I get better results when I turn all that crap off
(and even better results with the Use Google Libraries plugin), but
then that's me and my configuration. Your configuration may be
different, which is sorta the whole point.

-Otto
Sent from Memphis, TN, United States


More information about the wp-hackers mailing list