20101111 compression and web site performance - plembo/onemoretech GitHub Wiki

title: Compression and web site performance link: https://onemoretech.wordpress.com/2010/11/11/compression-and-web-site-performance/ author: lembobro description: post_id: 111 created: 2010/11/11 11:45:46 created_gmt: 2010/11/11 11:45:46 comment_status: open post_name: compression-and-web-site-performance status: publish post_type: post

Compression and web site performance

Compressing Web content can produce a much faster site for users.

So says Stephen Pierzchala in Compressing Web Content with mod_gzip and mod_deflate. This 2004 article contains a detailed treatement of the topic, with specific configuration examples and procedures for testing results. While its focus is on the bandwidth-reducing benefits of compression, improvements in performance are fully discussed (mod_gzip provided similar functionality for Apache 1.3).

System administrators who aren’t already using mod_deflate should consider exploring the potential performance gains it could provide. It’s compiled in but not configured by default in the shipping Apache 2 for Red Hat Enterprise Linux (RHEL).

In addition to the Linux Journal article cited above, more configuration examples can be found in Apache 2 mod_deflate Benchmark, Use mod_deflate to Compress Web Content delivered by Apache and howto: apache: mod_deflate.

It is important to note that to be effective, the mod_deflate configuration needs to be read in to each virtual host for a web server using Apache virtual hosts.

Here’s a deflate.conf file suitable for deploying to /etc/httpd/conf.d on a RHEL box, adapted from the articles and doc cited above (basically this config should cause everything but image files to be compressed):

# Configuration for mod_deflate
# If using Apache virtual hosts, read in to each vhost configuration with an
# Include statement, like "Include conf.d/deflate.conf".
<IfModule mod_deflate.c>
  # Compress everything
  # SetOutputFilter DEFLATE
  # Document types to compress
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
	
  # Compatibility with older browsers
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html
	
  # No compression of images
  SetEnvIfNoCase Request_URI .(?:gif|jp?g|png)$ no-gzip dont-vary
  # Ensure the right content gets delivered
  Header append Vary User-Agent env=!dont-vary
	
  # Logging to help in debugging
  DeflateFilterNote Input inputstream
  DeflateFilterNote Output outputstream
  DeflateFilterNote Ratio ratio
  LogFormat '"%r" %{outputstream}n/%{inputstream}n (%{ratio}n%%)' deflate
  CustomLog logs/deflate_log deflate
	
  # Zlib compression settings
  # Fragment size to be compressed at once
  DeflateBufferSize 8096
	
  # Compression level (range 1 [less] to 9 )
  DeflateCompressionLevel 9
	
  # Amount of memory used (range 1 - 9)
  DeflateMemLevel 9
	
  # Compression window size, the higher the better
  # (range 1 - 15)
  DeflateWindowSize 15
</IfModule>

On a standard RHEL system you can read this into each virtual host in httpd.conf like this (don’t forget conf.d/ssl.conf!):

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    ServerName myserver.example.com
    Options +IncludesNoExec
    ErrorLog /var/log/httpd/myserver-error_log
    CustomLog /var/log/httpd/myserver-access_log common
    Include conf.d/deflate.conf
</VirtualHost>

You can get more granular by only reading the config into specific or objects.

Copyright 2004-2019 Phil Lembo

⚠️ **GitHub.com Fallback** ⚠️