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:
- gzip foo.js
- change link in html to point to foo.js.gz instead of just .js
- 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 press streams; I just heard that you can also press the files once and leave them pressed.
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:
- gzip foo.js
- change link in html to point to foo.js.gz instead of just .js
- 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 press streams; I just heard that you can also press the files once and leave them pressed.
Share Improve this question edited Oct 17, 2008 at 15:33 Frew Schmidt asked Oct 17, 2008 at 14:28 Frew SchmidtFrew Schmidt 9,54417 gold badges66 silver badges88 bronze badges3 Answers
Reset to default 6As 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
Using gzip pression on a webserver usually means pressing the output from it to conserve your bandwidth - not quite what you have in mind.
Look at this description or This example
If you're using Apache, you use mod_deflate, and it presses 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 pressed here, transmitted, and unpressed there without the client having to even think about it.