[wp-hackers] Re: Packing JavaScript

Otto otto at ottodestruct.com
Wed Sep 19 18:17:49 GMT 2007


For everybody who's not Alex, here's my main argument:

Methods of optimizing javascript induced bandwidth:

1. GZIP type compression.
Advantages:
- Works on all hosts that WordPress works on, if you do it using PHP.
- Provides way more improvement than anything else (>90%)
- Works with all modern browsers.
Disadvantages:
- Requires caching on the server side to eliminate extraneous CPU use
(think of like WP-Cache for javascript).
- Won't work with some older browsers, but these are like <1% of the
total population of browsers.

2. Javascript compression.
Advantages:
- Compresses javascript in a way that will eliminate any need for any
server work of any kind.
- Can be made "safe" at the cost of making better optimizations.
Disadvantages:
- Only provides a ~50% improvement.
- Provides less than a 3% improvement if done in combination with GZIP
like compression.
- Adds extra maintenance overhead to the development side of things
(have to maintain compressed and decompressed versions, have to keep
them in sync, etc).
- Slows down client side processing by a measurable and non-trivial amount.

3. Combining multiple files into one
Advantages:
- Reduces HTTP overhead, which improves visible speed quite a bit for
a large number of files.
Disadvantages:
- Eliminates all the effects of browser caching. Now, instead of not
downloading files it already has, the browser will get those files
every time, since the file is combined with others. This can result in
a substantial bandwidth *increase* if not done carefully and
correctly. It's actually a deoptimization in many cases, and should be
used only where it makes sense. TinyMCE uses it because it makes sense
to do so there. It does not necessarily make sense in a global
perspective.

And there you go.


More information about the wp-hackers mailing list