Social Media

Simple Apache Performance Improvements

This post to collect together a number of simple performance improvements using apache. It demonstrates using mod_expires, mod_deflate, mod_cache and mod_headers.

.htaccess or httpd.conf

httpd.conf provides the core apache configuration, while .htaccess provides a directory specific configuration. The preference is to use httpd.conf where possible, because using htaccess results in a search for htaccess on every sub-directory of a request, for each request. Depending on your hosting this decision may be out of your hands.


mod_deflate tells apache to compress responses from your application server. The options are –

  • AddOutputFilterByType – To use this option you must enable mod_filter –
    LoadModule filter_module modules/
  • AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
  • Extension –
If you use AddOutputFilterByType then you need to make sure you have the mime-types defined

Other directives –

DeflateCompressionLevel – 1 to 9 – the higher the value, the greater compression but the cost is higher CPU

You can also enable mod_deflate logging to see the compression ratios on your files.

Putting it together –


This module sets the Expires HTTP header and max-age of Cache-Control in HTTP header.

The format is –

A typical configuration would be –


This plugin customises HTTP request and response headers, and we can use it to set the max-age on Cache-Control –


An ETag is a unique ID for a resource and is configured per server. The problem is that in some clustered environments you can end up caching the same resource due to them having different ETags. A decision on disabling ETag’s should be made on an environment basis, as disabling them forces the browser to rely on Cache-Control and Expires headers.

The syntax to disable is –


About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: