Forum Moderators: coopster

Message Too Old, No Replies

Gzip compression

Question about gzip from the server

         

Meno

3:16 pm on Jun 27, 2009 (gmt 0)

10+ Year Member



I know that ob_start("ob_gzhandler"); will compress html output from php. My question is: will it compress included .css an .js files? (I'm basically trying to get php to gzip jquery to make my site load faster.) I saw one source that said I had to add something to an htaccess file to make php gzip the .js files, but I'm not sure if ob_start("ob_gzhandler"); is allready doing it.

janharders

3:58 pm on Jun 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



are the .css and .js included with require (that is: included on the server and delivered as normal part of the document) or included on the clientside with <script> and <link>?

if they're included on the clientside, they won't be gzipped just because the php-script gzipped the document that includes them.

Meno

6:21 pm on Jun 27, 2009 (gmt 0)

10+ Year Member



they are included on the client side. is there a way to gzip the client included files?

[edited by: Meno at 6:22 pm (utc) on June 27, 2009]

janharders

6:34 pm on Jun 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yes - on the server-side :)

I guess the simplest way would be to add gzipped versions, say .css.gz and play with mod_mime, check out [httpd.apache.org...]
Especially AddEncoding ... you might want to do some work with mod_rewrite (or another directive, I'm not really an expert on that) to serve the ungzipped version of the file if the client indicates that he is not cappable to decompress gzip ...

Meno

3:53 pm on Jun 28, 2009 (gmt 0)

10+ Year Member



What do you think about this:

php_value output_handler ob_gzhandler

<filesMatch ".js$">
AddHandler application/x-httpd-php .js
</filesMatch>

Would that work?

janharders

4:36 pm on Jun 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



probably would, yes, if php is loaded as mod_php and imho, you don't necessarily need the FilesMatch since you're applying it only to .js anyhow.
Have you tested it?

Meno

5:54 pm on Jun 28, 2009 (gmt 0)

10+ Year Member



no. I just read it from a website. I see all sorts of different ways of doing this. Problem is that I don't know jack about apache.

janharders

6:28 pm on Jun 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just try it and use Live HTTP Headers (Firefox Plugin) or similar tools to see what is actually happening when you request a file from your server. Wether it works or not depends on the configuration of your server, so there will be some trial and error involved...