Compressing your files to load the pages faster has always been the preference for large files, but depending on your web host, it could be an incredible pain in the neck.
After telling us that it was coming in November of 2009, Google has finally announced as of April that “page load” time is actually a ranking factor now.
For quite a while, (actually since preparing for my Pubcon 2008 hosting presentation), I’ve been looking for a compression option that will work easily, and it turns out that it’s been there right under my nose all along.
Okay, maybe “right under my nose” is an exaggeration, but I was stunned to find out that this is nothing new, and the solution has been around for years. Doh!
On any site hosted on an Apache / PHP web server, all you have to do is paste this code into the top of any page you want compressed, and that’s it… Page compression will be on “automatic”.
<? ob_start(“ob_gzhandler”); ?>
In most WordPress sites, I simply placed it at the top of my header.php file, and saved. A quick check of the site shows it working great.
*** update 5/24/2010 - It seems that when using this for WordPress via header.php, the title tag that gets generated for the site home page by the All-in-One SEO plugin is not working. This stinks, so we’re looking for a fix…
On this particular site, where I’m using the Thesis theme, simply copy/paste into the “Additional Scripts” area in your Thesis site options.
(This does *not* cause a problem for All in One SEO)
On a static .html, .htm, or .php site, just paste it into the shared site-wide header, right at the very top, even before the Doc type statement and other meta data.
It works fine in OC commerce too, after placing it in the top of this file – domain.com/www/includes/application_top.php.
I havent yet tried it on Drupal, Joomla, or Zencart yet because we’ve used other configurations already, but I see no reason it shouldn’t work.
The average data reduction we’re getting is about 70%, but we’ve seen as high as 84%. All in all, this php compression has worked instantly every single place we’ve tried it, other than on a Windows server, where (like so many things Microsoft) it just doesn’t work ;(
Before trying the code, be sure verify whether your site is serving compressed pages . If it’s not, just add the code, and test again to see the automatic change.
Like I said, this php compression solution has been under my nose for a long time, and now it’s under yours too.











Twitter
LinkedIn
Facebook
Youtube
{ 3 comments… read them below or add one }
Hopefully I found a solution to the All-In-One-SEO conflict. Adding this to the htaccess file both compressed the page for me and also allowed the title to work correctly:
# Compress file type by extension:
<Files *.php>
SetOutputFilter DEFLATE
</Files>
Please test this out so we can get a good confirmation on how well it works.
So this didn’t work for me, neither did Heather’s idea. However, I did find out how to do it. My site is hosted on Fatcow and in order to do it there you have to do it through Fatcow’s control panel.
Output encoded/compressed content (Gzip/Zlib) from your site (Advanced users only!)
To allow for PHP scripts to output Gzip/Zlib encoded content, accepting the “Accept-Encoding” request-header field from browsers is enabled on the FatCow platform. Learn more about the Accept-Encoding request-header field header at Connected.
Zlib compression enables you to transparently read and write gzip (.gz) compressed files. The encoding is helpful for PHP forums and other applications in which compression and saving bandwidth matter, as it will send back smaller amounts of data (compressed, rather than the full data).
You must enable encoding at the script level or in the PHP.ini file. It’s not possible to enable it at the .htaccess level.
To enable encoding in the php.ini file:
1. Log into your control panel
2. Under Scripting and Add-Ons, select CGI and Scripted Language Support
3. Select PHP Scripting
4. Your php.ini file is displayed at the bottom of the page
5. Find the line that contains:
zlib.output_compression = Off
6. Chang this line and add another as shown:
zlib.output_compression = On
zlib.output_compression_level = 7
7. Click Save
Hmm, I’ve found that to be pretty universal, but great to hear that your host has the process available too – thanks for the details!