WP-Cache2 and Gzip
WP-Cache2 is a great way to speed up high-trafficked WordPress sites by caching their output as static pages. The only downside is that you have to turn off gzip compression in WordPress, which can actually make some pages slower to download. Wouldn’t it be great if you could have the best of both worlds? It appears that you can.
I think the problem was that with WP’s gzip turned on, it was caching the gzipped output. I edited wp-cache-phase1.php and put in the following:
if ( extension_loaded('zlib') ) ob_start('ob_gzhandler');
right above this line:
foreach ($meta-»headers as $header) {
And it seems to work beautifully. That caches the plaintext, but gzips the text before delivering on cached hits. Might work for people who can’t mess with server configuration files.
You can see it in action over at the WP Hooks Database.


I’m going to try that out here on WP.com.
Matt
January 31, 2006 at 2:30 pm
Hmm, it looks like we’re already doing gzip at the server level, so not needed.
Matt
January 31, 2006 at 2:43 pm
Yeah, if you control your server, you can always just do that… I’m hoping that this will be of some use to the many people on shared hosting.
Mark Jaquith
January 31, 2006 at 5:57 pm
well, if only WP-Cache worked with WP2, the world would’ve been a much better place!!
Amit Gupta
February 17, 2006 at 6:57 pm
WP-Cache2 works just fine with WordPress 2.0 and 2.0.1 on every server I’ve installed it on.
Mark Jaquith
February 19, 2006 at 4:43 am
I tried this but WP_Cache2 plugin is couching up this error:
Warning: GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.
WP-Cache is Disabled
Harshblogger
March 11, 2006 at 5:22 pm
Disable Gzip compression in WordPress… let WP-Cache2 (modified) handle it.
Mark Jaquith
May 2, 2006 at 7:47 am
Hello Mark,
The latest version of WP-Cache is 2.0.17; and if it detects GZip, with or without your mod above, it will disable caching. So, I’m not too sure what you mean by comment #7…..
Computer Guru
May 3, 2006 at 4:31 am
WP-Cache2 disables caching if it detects that you have enabled gzip compression from within WordPress. With my mod you are doing the compression from within WP-Cache2 and so you should turn of gzip compression in WordPress. The problem is that if you do the compression in WordPress, it gets cached as compressed code. By doing in in WP-Cache2, you can save the cache as plaintext, but compress it when you deliver it.
Mark Jaquith
May 3, 2006 at 4:38 am
Ouch… Thanks for clearing that up..
I’m glad I checked back here for a reply, because I had gone ahead and implemented your patch, then removed all gzip checks from Gallir’s code, and on top of that enabled WP gzip….. It “worked” great until I realized it wasn’t caching anything
Thanks Mark!!!
Computer Guru
May 3, 2006 at 5:11 am
[...] I’ve since installed WP-Cache 2 with the required WordPress 2.0/PHP 5 fix and Mark Jaquith’s gzip compression patch. I tested it to make sure it works, but I’m leaving it off until the next time the barbarians show up at the gate, as it screws with some dynamic code I have and I haven’t figured out how to get it to execute the code every time. Yet. [...]
Lunacy Unleashed » Blog Archive » I got slashdotted!
June 3, 2006 at 1:11 am
[...] http://chrisstormer.com/2006/07/08/bad-behavior-wp-cache-gzip-solution/ or http://markjaquith.wordpress.com/2006/01/31/wp-cache2-and-gzip/ [...]
www.ngtech.gr » Modifying WP-Cache 2.0 to generate and cache gzipped output once and serve it multiple times
October 22, 2006 at 10:13 am
How To Enable Gzip With WP-Cache2
I’ve made one last tweak to my site to improve performance that I’d like to highlight to other WordPress users who use the WP-Cache2 plugin. WP-Cache2 unfortunately doesn’t work with gzip compression, which means that some of your pa…
Connected Internet
January 2, 2007 at 11:02 am
[...] Source [...]
Enable Gzip Compress on Wordpress with WP-Cache 2.x » My Digital Life
March 10, 2007 at 7:14 am
[...] Mark Jaquith and Chris Stormer have found that a minor change in the the code of the plugin can turn on GZip [...]
Eite Webs - Official Blog » Blog Archive » Save Bandwidth with gzip Compression
March 22, 2007 at 4:14 am
[...] Mark Jaquith and Chris Stormer have found that a minor change in the the code of the plugin can turn on GZip [...]
Save Bandwidth with gzip Compression » Ajay - On the Road called Life!
March 23, 2007 at 3:50 am
Strange… I wonder why this isn’t just made an option in wp-cache. So you disable gzip in WP itself and enable again from wp-cache options panel.
Seems to be working for me.
Robert Accettura
April 22, 2007 at 12:52 pm
I tried adding above line , but as soon as i enable gzip, cache gets disabled.
Kamran
Kamran
May 12, 2007 at 1:10 pm
Kamran: Read carefully, please. You have just to add the line to wp-cache-phase1.php, that’s all… DO NOT enable gzipping in WP options panel, leave it switched off. Then take a look at HTTP headers sending by your server – gzipping works. Tested on WordPress 2.1.3 + WP-Cache 2.1.1
Honza
May 16, 2007 at 9:30 am
coolness.. at first im a little bit skeptic trying it out, but yeah, my page did load faster.. good job..
=)
dude alert!
August 4, 2007 at 8:42 pm
[...] your content. It turns out that it only requires one line of code. You can thank WordPress guru, Mark Jaquith, for figuring it out a little over a year and a half ago. Until I get some people to test it, [...]
WP-Cache NoSymlink Now with gzip
August 27, 2007 at 2:36 am
this does not work when i test it with a compression check, still shows my site as being uncompressed
mharacz
September 21, 2007 at 7:40 pm
[...] This was not trivial as the standard WordPress gzip option was interfering with our caching plugin. I found a fix for this though and ran a few tests: the filesize of our HTML code is reduced by around 84%: from around [...]
Some Website Optimizations at BlenderNation
October 20, 2007 at 12:11 pm
I wonder If it does allow you to use WP-Polls for example. Do you guys have any experience?
MeME
April 17, 2008 at 5:13 am
Thanks this really speeds up my blog
Web Hosting Coupon Codes
September 19, 2008 at 7:32 pm
[...] WP-Cache2 and Gzip ” Mark on WordPress [...]
Obama Fumbles and Makes the Case Why Hilary Clinton Should Have Been President as He Announces Volcker Chairman-Designate of the Newly Formed Economic Recovery Advisory Board « But As for Me!
November 26, 2008 at 1:38 pm