Use GZIP compression in HTTP servers

Recently I have found a great solution for implementing a HTTP server in devices with limited memory (like the ones based on USBizi chip). The problem I faced when implementing one was that when the device is serving pages/scripts/images/etc it needs to load them to memory from internal resources or e.g. sd card, and save them to the result stream. It all involves a lot of memory as it’s easy for html or javascript files to have 10KB+. For USBizi that’s a lot. At the beginning i was only using minified javascript libraries and i guess there are also tool to minify my own html files as well. While investigating options i have found a simple yet perfect solution for this problem: using GZIP! The idea is simple, you only store the compressed versions of your files on the device. When your web server sends a response, just include this header:

context.Response.Headers.Set("Content-Encoding", "gzip");

Modern browser will decompress the file before rendering it. This operation is transparent for the user. This option can be turned on in IIS or Apache, I just wasn’t aware of it and how well it fits to our low memory constraints. I hope you can benefit from this. For those of you who already know that, sory for wasting your time :wink:

Hi Gralin,
that is indeed a good idea…
so you are saying that you gzipped all your file into one file and served them all you have to gzip every single one of the files separately?

maybe there is tool out there that can automate this process…
thanks for sharing…

Jay.

@ Jay Jay, it’s either way. If you put all your javascripts inline in the html and gzip it you will get a better compression comparing to using separate files. However when using multiple files you can manipulate with the cashing so that the browser does not ask for your js/css files each time the user reloads the page. This way you will mostly only return one small gzipped html file.

Yes, it’s called 7zip :wink: You can include it in your build script to generate .gz files from all your web content. After that just copy those file on a SD card or do this before build if you want them to be included as resources.

Thanks Gralin,
A soon as i have a bit of time i will play with it and write a tutorial on all different options.

As always keep up the great work …

Thanks.
Jay.