Forum Moderators: phranque

Message Too Old, No Replies

AddHandler and ob gzhandler output

addhandler, gzip, php

         

Meno

11:08 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



I'm trying to get .css and .js files to be handled by ob_gzhandler. I can get php to gzip html output, that's easy. ob_gzhandler is working on .php files just fine. I'm trying to get apache to give the same treatment to css and js files. I have this in my .htaccess:

AddHandler application/x-httpd-php .css

With the above, in the htaccess, it does not gzip css files at all. With the following...

AddHandler x-httpd-php .css

...it does gzip, but the css doesn't work at all, and the page loads without style. So my first question is: what does the "application/" thing do? My second question is: why doesn't "AddHandler application/x-httpd-php .css
" work, when many people on the web say that it should? (I've tried addType as well, with the same results.)

encyclo

11:17 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The latter is correct, but then you must define the mime-type for the CSS/JS file with PHP:

<?php header('Content-Type: text/css'); ?>

Be careful with caching, though, you may win out with file-size, but that does not help if you don't allow the generated file to be cached as the CSS file would be downloaded for every single pageview.

Caterham

12:00 am on Jun 30, 2009 (gmt 0)

10+ Year Member



why doesn't "AddHandler application/x-httpd-php .css
" work, when many people on the web say that it should?

You'll need a handler which handles the request if the handler is set to application/x-httpd-php. mod_php's handler will handle the request, if the handler application/x-httpd-php was assigned. If you're using php via fastcgi etc. you'll have your own handler defined.

mod_php5 acts if the handler was set to application/x-httpd-php, application/x-httpd-php-source or php5-script.

Meno

3:26 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



encyclo, <?php header('Content-Type: text/css'); ?> worked. thanks. But, now, how do I tell if my css file is being cached or not? I can't find anything in firebug to tell me anything about caching.

Meno

3:36 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Caterham, I guess mod_php's handler isn't working on my server. How do you define your own handler?