views:

3396

answers:

7

What advantages do either method offer for html, css and javascript files served by a LAMP server. Are there better alternatives?

The server provides information to a map application using Json, so a high volume of small files.

See also Is there any performance hit involved in choosing gzip over deflate for http compression?

+1  A: 

The main reason is that deflate is faster to encode than gzip and on a busy server that might make a difference. With static pages it's a different question, since they can easily be pre-compressed once.

Joachim Sauer
presumably with gzip you can't start transmitting the header until you've obtained, stored and compressed *all* the data? (because you need the checksum to create the header)
OJW
In the gzip format, the checksum comes at the end of the file, specifically so one can start writing deflate blocks as they are processed without having to hold everything up.
Jack Lloyd
A: 

if I remember correctly

  • gzip will compress a little more than deflate
  • deflate is more efficient
JimmyJ
gzip is deflate with a header. And HTTP 1.1 deflate is actually zlib (which is also a wrapper around deflate)
David Murdoch
+1  A: 

I think there's no big difference between deflate and gzip, because gzip basically is just a header wrapped around deflate (see RFCs 1951 and 1952).

schnaader
+22  A: 
Jeff Atwood
Seems to be mainly the checksum, which would match with the smaller difference on faster systems.
schnaader
On the Intel chips it doesn't make a bit of difference, since they get that fancy SSE4.2 "CRC32" instruction...
Ant P.
only the very very newest Intel chips have that, though -- Core i7 or better
Jeff Atwood
Not to mention that zlib doesn't have support for the extension, and even if it did, the CRC32 instruction in SSE 4.2 uses the polynomial 1EDC6F41, and the gzip format uses the polynomial EDB88320 - totally different algorithms, effectively.
Jack Lloyd
Jeff, do you have the graph for this?
David Murdoch
And since deflate is faster, why is SO using gzip?
David Murdoch
Deflate is actually the zlib format, which is raw deflate data with a much smaller header and the computationally cheaper Adler32 checksum on the end.
Andrew Dunn
+2  A: 

mod_deflate requires fewer resources on your server, although you may pay a small penalty in terms of the amount of compression.

If you are serving many small files, I'd recommend benchmarking and load testing your compressed and uncompressed solutions - you may find some cases where enabling compression will not result in savings.

Dave R.
A: 

Just for future reference:

Under a debian system (I'm on ubuntu) with Apache2 and the deflate module already installed (which it is by default), you can enable deflate compression in two easy steps:

a2enmod deflate
/etc/init.d/apache2 force-reload

And you're away! I found pages I served over my adsl connection loaded MUCH faster!

aidan
A: 

There shouldn't be any difference in gzip & deflate for decompression. Gzip is just deflate with a few dozen byte header wrapped around it including a checksum. The checksum is the reason for the slower compression. However when you're precompressing zillions of files you want those checksums as a sanity check in your filesystem. In addition you can utilize commandline tools to get stats on the file. For our site we are precompressing a ton of static data (the entire open directory, 13,000 games, autocomplete for millions of keywords, etc.) and we are ranked 95% faster than all websites by Alexa. Faxo Search. However, we do utilize a home grown proprietary web server. Apache/mod_deflate just didn't cut it. When those files are compressed into the filesystem not only do you take a hit for your file with the minimum filesystem block size but all the unnecessary overhead in managing the file in the filesystem that the webserver could care less about. Your concerns should be total disk footprint and access/decompression time and secondarily speed in being able to get this data precompressed. The footprint is important because even though disk space is cheap you want as much as possible to fit in the cache.

Steven
GZip probably checks the checksum on decompression, hence the speed difference for decompression.
Seun Osewa