Skip to content Skip to sidebar Skip to footer

How Do I Set Up Gzip Compression On A Web Server?

I have an embedded webserver that has a total of 2 Megs of space on it. Normally you gzip files for the clients benefit, but this would save us space on the server. I read that y

Solution 1:

As others have mentioned mod_deflate does that for you, but I guess you need to do it manually since it is an embedded environment.

First of all you should leave the name of the file foo.js after you gzip it.

You should not change anything in your html files. Since the file is still foo.js

In the response header of (the gzipped) foo.js you send the header

Content-Encoding: gzip

This should do the trick. The client asks for foo.js and receives Content-Encoding: gzip followed by the gzipped file, which it automatically ungzips before parsing.

Of course this assumes your are sure the client understands gzip encoding, if you are not sure, you should only send gzipped data when the request header contains

Accept-Encoding: gzip

Solution 2:

Using gzip compression on a webserver usually means compressing the output from it to conserve your bandwidth - not quite what you have in mind.

Look at this description or This example


Solution 3:

If you're using Apache, you use mod_deflate, and it compresses on the fly.

I think you're getting confused by thinking that if you gzip something it has to be a file. Instead, think about how a file is just a stream of data, and that stream of data can get compressed here, transmitted, and uncompressed there without the client having to even think about it.


Post a Comment for "How Do I Set Up Gzip Compression On A Web Server?"