Skip to main content

Optimize web pages for 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. Compressing 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:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript

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/ .

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

Kornel is a dedicated software engineer. In the Pronovix he spends his time architecting and developing Drupal-related services. He is a proud member of the International and Hungarian Drupal community, having contributed several modules and core patches. Kornel is enthusiastic about the web, programming and open source technologies, his thirst for knowledge doesn't stop at the computer: in his offline life he is interested in fitness, nutrition and neuroscience.

Newsletter

Articles on devportals, DX and API docs, event recaps, webinars, and more. Sign up to be up to date with the latest trends and best practices.

 

Subscribe