More GZip silliness

16 Nov 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:
    1. AddType application/x-compress .Z
    2. AddType application/x-gzip .gz .tgz
    3. AddType application/x-httpd-php .php
    4. AddType application/x-httpd-php .php3
    5. AddOutputFilterByType DEFLATE text/html
    6. AddOutputFilterByType DEFLATE text/plain
    7. AddOutputFilterByType DEFLATE text/xml
    8. AddOutputFilterByType DEFLATE application/x-httpd-php
    9. AddOutputFilterByType DEFLATE application/x-javascript
    10. AddType text/html .js .js.gz
    11.  
    12. AddOutputFilter INCLUDES .js .js.gz
  • The CSS for some reason had to be done differently. In an htaccess file in a CSS ONLY directory.
    1. AddHandler application/x-httpd-php .css
    2. php_value auto_prepend_file gzip-css.php
    3. php_flag zlib.output_compression On
  • Additionally put a file called gzip-css.php in that directory. It’s contents:
    1. ob_start ("ob_gzhandler");
    2. header ("content-type: text/css; charset: UTF-8");
    3. header ("cache-control: must-revalidate");
    4. $offset = 60 * 60;
    5. $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
    6. header ($expire);
    7. ?>

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??

  • Google Buzz

5 Comments

Avatar

Mike Schinkel

December 4th, 2007 at 11:54 pm

Love this post! Wish I could get it to print correctly, though! ‘-p

(Doesn’t print correctly in either IE7 or FF2)

Avatar

Glen Lipka

December 5th, 2007 at 7:04 pm

Ok, I added a new print.css which cleans it up.
Is that better?

Avatar

Mike Schinkel

December 5th, 2007 at 8:53 pm

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…

Avatar

css second way

January 12th, 2008 at 7:10 pm

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

Avatar

me

March 9th, 2008 at 8:41 am

>> 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.

Comment Form

About commadot.com

Started in 1996, Glen Lipka has been been randomly publishing about User Experience, Technology, Human Psychology and other subjects.

Good Karma

Did you save or make money off this blog?

Contact Glen or try to IM me below.

Archives