 ##  [Optimize web pages for bandwidth ](/blog/optimize-web-pages-bandwidth) 

Senior Developer

Jan 21, 2010

 

Few people would consider optimizing for bandwith, but sometimes it's worth it, for example if you have a strict limit on a hosting solution, or if you pay for the bandwidth (like on amazon ec2). Even if you don't have those restrictions it could mean the difference between "that was slow" and "that was fast". In this article we're going to focus on the server side settings that you could consider to achieve this goal.

### Drupal css/javascript minifier

Every performance related article strongly recommends enabling this feature, mainly because it will reduce the number of http queries needed to get everything rendered. It also gives you better compression ratios (css files are very repetitive). See next paragraph:

### mod\_deflate

Most people have heard about this. **Compress**ing web pages with gzip is an easy win and it can save you **up to 60%** of your bandwith. To use it, you enable the `mod_deflate` apache module: `a2enmod deflate` Fewer people know you can also compress css, javascript and xml files. Edit `/etc/apache2/modules-enabled/deflate.conf`: `<ifmodule mod_deflate.c=""><br></br>AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript<br></br></ifmodule>`  
The limiting resource on todays webservers is usually memory and not cpu. To improve efficiency, we can **finetune the compression level**. For example by raising it from the default 7 up to 9: `DeflateCompressionLevel 9` With that you can get a compression ratio that sometimes crawls over 80%! This tweak is not fit for all cases, it depends on your server configuration, the pages you serve, any additional services you run. Sometimes it's smarter to even lower this level to get higher throughput, but I think 9 is where you can start experimenting. You can check if your site uses gzip compression at [http://www.whatsmyip.org/http\_compression/](http://www.whatsmyip.org/http_compression/) .

### mod\_expires

With this module you can tell the client that this file **wont change for a certain time**, so it shouldn't be downloaded again. Drupals .htaccess file contains a conditional rule about the default expire time of the files. You can enable the module through: `a2enmod expires`

### Optimize images!

Most people nowadays know about **optimizing .png files**. It makes your file a few bytes smaller without degrading the quality of the file. You can do this with tools like **optipng** and **pngcrush**. Optipng is easier to handle, and it's perfect if you just want to make the image smaller in size. Doing this once will **save you up to 10%** of your file size. `apt-get install optipng` Fewer people however know that you can do the same with **.jpg files**. You can optimize the the Huffman table with tools like **jpegtrans**. This generally will **save 4-5%** per image both optimizations can mean a lot if you host image galleries for example. `libjpeg-progs`