Skip to content

How to Configure Apache mod_expires for Caching

DodaTech Updated 2026-06-24 2 min read

mod_expires sets cache expiry headers that tell browsers how long to keep static resources locally. Proper Caching reduces server load and improves page load times. This guide walks through the specific troubleshooting steps to diagnose and resolve Caching issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

No expiration headers set (browsers re-request every resource)

Wrong: No cache control headers

ExpiresActive On\nExpiresByType image/png "access plus 1 year"\nExpiresByType text/css "access plus 1 month"\nExpiresByType application/javascript "access plus 1 month"\nExpiresDefault "access plus 1 day"

Right: Setting Expires headers per MIME type

Output

mod_expires configured:\n  images: 1 year\n  CSS/JS: 1 month\n  Default: 1 day

Prevention

To avoid future issues, follow these best practices:

  • Enable mod_expires with a2enmod expires
  • Set long cache times for versioned static assets
  • Use shorter cache times for non-versioned resources
  • Combine with mod_headers for Cache-Control fine-tuning
  • Test with browser developer tools to verify cache headers

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with mod expires

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world APACHE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the difference between access plus and modification plus?|||access plus specifies cache time from the request time. modification plus specifies from the file last-modified time.
How long should I cache static assets? Images and fonts: 1 year. CSS/JS with versioning: 1 year. CSS/JS without versioning: 1 week or 1 month.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro