user39980
user39980

Reputation:

GZipping website (js, css, php)

I have been reading different articles on GZipping and am wondering what is the best way to gzip my files including:

I saw this article: http://blog.mycila.com/2009/08/godaddy-gzip-compression.html

Kind of blurry on the whole deal.

Any suggestions?

Upvotes: 1

Views: 399

Answers (2)

Havenard
Havenard

Reputation: 27864

In .htaccess place this line:

SetOutputFilter DEFLATE

Thats it. Apache will now compress all output.

To improve performance, you can chose not to compress files that are already compressed, for instance:

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpeg|jpg|png|tgz|gz|zip|gz2|rar)$" no-gzip dont-vary

deflate_module must be enabled in httpd.conf to take effect.

You can also implement that via PHP, but only PHP files would be compressed.

Upvotes: 1

cletus
cletus

Reputation: 625087

Basically you want to GZip everything but if you have to watch out for certain versions of IE6 that don't handle GZipping of secure content.

You can do this in PHP or with, say, Apache extensions. I generally prefer to do it with PHP as you can better control the logic but the other choice is perfectly valid too. In PHP it can be as simple as:

ob_start('ob_gzhandler');

at the top of your code.

There are a lot of issues with this such as effective caching and so on so I am going to point you to Supercharging Javascript in PHP and Supercharging CSS in PHP.

Upvotes: 0

Related Questions