Recommended Apache configurations

If you are serving a long document from an Apache web server, we recommend you make the following additions or changes to your httpd.conf or .htaccess file.

AddDefaultCharSet UTF-8 # 1
      # 480 weeks
      <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> # 2
      Header set Cache-Control "max-age=290304000, public"
      # 2 DAYS
      <FilesMatch "\.(xml|txt)$">
      Header set Cache-Control "max-age=172800, public, must-revalidate"
      # 2 HOURS
      <FilesMatch "\.(html|htm)$">
      Header set Cache-Control "max-age=7200, must-revalidate"
      # compress text, html, javascript, css, xml:
      AddOutputFilterByType DEFLATE text/plain # 3
      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
      # Or, compress certain file types by extension:
      <Files *.html> 
      SetOutputFilter DEFLATE


See Odd characters in HTML output in Bob Stayton's book DocBook XSL: The Complete Guide for more information about this setting.


These lines and those that follow cause the browser to cache various resources such as bitmaps and JavaScript files. Note that caching JavaScript files could cause your users to have stale search indexes if you update your document since the search index is stored in JavaScript files.


These lines cause the the server to compress html, css, and JavaScript files and the brower to uncompress them to improve download performance.