More GZip silliness

By | November 16, 2007

I wanted to gzip the javascript and css files on marketo.com. Again, this technology should be DEFAULT on every web host in the world. I have no idea why they don’t have this turned on. Anyway, after another couple of hours, I found this solution which seemed to work. Specifically, it only worked on MediaTemple. It did not work on this server (Bluehost). I am not sure why. Actually, I am really confused.

The method was this:

  • In the root of the web edit file .htaccess. It should contain the following:
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE application/x-httpd-php
    AddOutputFilterByType DEFLATE application/x-javascript
    AddType text/html .js .js.gz
    
    AddOutputFilter INCLUDES .js .js.gz
  • The CSS for some reason had to be done differently. In an htaccess file in a CSS ONLY directory.
    AddHandler application/x-httpd-php .css
    php_value auto_prepend_file gzip-css.php
    php_flag zlib.output_compression On
  • Additionally put a file called gzip-css.php in that directory. It’s contents:
    ob_start ("ob_gzhandler");
    header ("content-type: text/css; charset: UTF-8");
    header ("cache-control: must-revalidate");
    $offset = 60 * 60;
    $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
    header ($expire);
    ?>

Ok, so that ended up compressing all of the files I needed. JS, CSS and PHP. So now, why doesn’t it work in BlueHost??

5 thoughts on “More GZip silliness

  1. Mike Schinkel

    You da man! I can’t tell you how often as find blogs that won’t print and when I mention it nobody responds or fixes it. Thanks for the effort.

    BTW, I like you blog and as both entrepreneurs and web developers we seem to be kindred spirits…

    Reply
  2. css second way

    AddOutputFilterByType DEFLATE text/css application/x-javascript
    CacheEnable disk /directorio1/directorio2/style.css
    CacheEnable disk /directorio1/directorio2/print.css
    CacheEnable disk /directorio3/directorio4/scripts.js

    add ur own

    Reply
  3. me

    >> Again, this technology should be DEFAULT on every web host in the world. I have no idea why they don’t have this turned on.

    Because older browsers can’t handle compressed css and javascript.

    Additionally, your php compression should be handled inside php.ini.

    Reply

Leave a Reply