Add Cache-Control Headers
How to add cache control headers to your website
Configure Browser Caching with Cache-Control Headers
Example 1 - Recommended (Balanced)
# ------------------------------------------------------------
# Elements Hosting: Balanced browser caching
# ------------------------------------------------------------
<IfModule mod_expires.c>
ExpiresActive On
# Default for file types not explicitly listed below
ExpiresDefault "access plus 1 hour"
# HTML documents
ExpiresByType text/html "access plus 1 hour"
# Stylesheets
ExpiresByType text/css "access plus 1 year"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
# Fonts
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
# Images
ExpiresByType image/avif "access plus 30 days"
ExpiresByType image/webp "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
ExpiresByType image/png "access plus 30 days"
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/svg+xml "access plus 30 days"
ExpiresByType image/x-icon "access plus 30 days"
# PDF documents
ExpiresByType application/pdf "access plus 7 days"
</IfModule>
<IfModule mod_headers.c>
# RapidWeaver normally cache-busts CSS and JavaScript when publishing.
# Fonts are also suitable for long-lived immutable caching.
<FilesMatch "\.(?:css|js|mjs|woff2?|ttf|otf|eot)$">
Header merge Cache-Control "immutable"
</FilesMatch>
# Do not cache dynamic PHP responses.
<FilesMatch "\.php$">
# Remove headers generated in the normal response-header table.
Header unset Expires
Header unset Cache-Control
Header unset Pragma
# Remove equivalent headers from Apache's always header table.
Header always unset Expires
Header always unset Cache-Control
Header always unset Pragma
# Apply one authoritative no-cache policy.
Header always set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
Header always set Pragma "no-cache"
</FilesMatch>
</IfModule>Balanced durations
Resource
Origin cache lifetime
Example 2 - Frequently Updated Websites
Frequently updated durations
Resource
Origin cache lifetime
Example 3 - Aggressive Caching
Aggressive caching durations
Resource
Origin cache lifetime
Cloudflare Browser Cache TTL

Last updated
Was this helpful?

