views:

76

answers:

3

Hy can anyone that is using gzip for html js php and css how to implement this on a server.

What I want to know is :

  1. What do I have do write in .htacces 2.What and from where to download
  2. most important does it make a diferance and does it pay off.

Thx for your help and time

A: 

It does pay off: HTML pages, being clear text, can often be zipped massively, by up to 90 percent.

Gzipping usually needs to be activated in your central server configuration, though, not .htaccess.

If you are on a shared hosting server, chances are it is already installed and turned on.

Use something like Firebug's "Net" tab to find out. Make a request to a page on your server, and click open the file view. If the response headers contain Content-Encoding: gzip, gzipping is already activated.

Pekka
thx pekka but that is not enough
John the horn
@John what else do you need? You're not saying what server you're on, and it's not sounding that you have access to its config, so it's difficult to say more.
Pekka
@Pekka your advise was comprehensive but I do not know what kind of server it is or what to config in it THX for your time
John the horn
+1  A: 

You need mod_deflate or mod_gzip to be enabled on your httpd.conf. After that, you should put the following lines into your configuration or .htaccess file.

Apache 1.3.x:

mod_gzip_on Yes  

mod_gzip_item_include mime ^application/x-javascript$  
mod_gzip_item_include mime ^application/json$  
mod_gzip_item_include mime ^text/.*$  

mod_gzip_item_include file \.html$  
mod_gzip_item_include file \.php$  
mod_gzip_item_include file \.js$  
mod_gzip_item_include file \.css$  
mod_gzip_item_include file \.txt$  
mod_gzip_item_include file \.xml$  
mod_gzip_item_include file \.json$  

Header append Vary Accept-Encoding

Apache 2.0

AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/json   
Header append Vary Accept-Encoding
galambalazs
thx @galambalazs for you answer and time
John the horn
It’s *application/javascript* and not *application/x-javascript*.
Gumbo
*"application/javascript: Defined in RFC 4329 but not accepted in IE 8 or earlier"* - wikipedia
galambalazs
A: 

Does it pay off? There are scenarios, where it will be even slower with compression turned on..

When you turn on compression, Apache needs to wait, till all PHP is completed, before sending any content to the client. With compression turned off, Apache could start sending, with the first echo statement.

Due to this, the client may get the head-section fast, where it gets the info which stylesheets and JS to load and can request them, whil the rest of the PHP script is still generating HTML.

So when your PHP takes time to run, you should most likely not activate compression.

Still there are a lot of positiv effects of compression.

JochenJung