views:

750

answers:

3

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 you can just gzip the js file and save it on the server. I tested that on IIS and I didn't have any luck at all. What exactly do I need to do on every step of the process to make this work?

This is what I imagine it will be like:

  1. gzip foo.js
  2. change link in html to point to foo.js.gz instead of just .js
  3. Add some kind of header to the response?

Thanks for any help at all.

-fREW

EDIT: My webserver can't do anything on the fly. It's not Apache or IIS; it's a binary on a ZiLog processor. I know that you can compress streams; I just heard that you can also compress the files once and leave them compressed.

A: 

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

Dave R
I know that, but I have read that you can compress static files, and if I can do that I'll do it.
Frew
A: 

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.

Andy Lester
+2  A: 

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
Pat