Skip to main content

.htaccess Cache Expiration

Cache Expiration

Clients can use caching to save time by avoiding repeated requests and using previously requested resources that are still valid.

To serve resources with a far-future expiration date the the mod_expires module is used, together with Cache-Control and Expires headers.

<IfModule mod_expires.c>
# Enable browser caching
ExpiresActive on
# Set the default caching duration
ExpiresDefault "access plus 1 month"

# Change the caching duration by file type

ExpiresByType text/css "access plus 1 year"

# Data interchange
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rdf+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/schema+json "access plus 0 seconds"
ExpiresByType application/geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/calendar "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"

# Favicon (cannot be renamed!) and cursor images
ExpiresByType image/ "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"

ExpiresByType text/html "access plus 0 seconds"

# JavaScript
ExpiresByType text/javascript "access plus 1 year"

# Manifest files
ExpiresByType application/manifest+json "access plus 1 week"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"

# Markdown
ExpiresByType text/markdown "access plus 0 seconds"

# Media files
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/bmp "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
# PNG and animated PNG
ExpiresByType image/apng "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
# HEIF Images
ExpiresByType image/heic "access plus 1 month"
ExpiresByType image/heif "access plus 1 month"
# HEIF Image Sequence
ExpiresByType image/heics "access plus 1 month"
ExpiresByType image/heifs "access plus 1 month"
# AVIF Images
ExpiresByType image/avif "access plus 1 month"
# AVIF Image Sequence
ExpiresByType image/avis "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"

# WebAssembly
ExpiresByType application/wasm "access plus 1 year"

# Web fonts
# Collection
ExpiresByType font/collection "access plus 1 month"
# Embedded OpenType (EOT)
ExpiresByType application/ "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"
# OpenType
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/otf "access plus 1 month"
# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"
# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 month"

# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"

Fetching resources over the network is both slow and expensive: the download may require multiple roundtrips between the client and server, which delays processing and may block rendering of page content, and also incurs data costs for the visitor. All server responses should specify a caching policy to help the client determine if and when it can reuse a previously fetched response.

Table of Contents