Speed up your site with Caching and cache-control
Caching with .htaccess and Apache will take your website and your web skills to the next level. This is some technical and advanced methods condensed to simple htaccess code examples for you. But you must take the time to understand caching with cache-control and other headers and HTTP options before you implement on a production server.
More detailed article: Speed Up Sites with htaccess Caching.
Easy Apache Speed Tips Articles
- Turn On Compression
- Add Future Expires Header
- Add Cache-Control Headers
- Turn Off ETags
- Remove Last-Modified Header
Caching with both mod_expires + mod_headers
# Turn on Expires and set default to 0 ExpiresActive On ExpiresDefault A0 # Set up caching on media files for 1 year (forever?)ExpiresDefault A29030400 Header append Cache-Control "public" # Set up caching on media files for 1 weekExpiresDefault A604800 Header append Cache-Control "public" # Set up 2 Hour caching on commonly updated filesExpiresDefault A7200 Header append Cache-Control "proxy-revalidate" # Force no caching for dynamic filesExpiresActive Off Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" Header set Pragma "no-cache"
Caching with mod_headers
# 1 YEARHeader set Cache-Control "max-age=29030400, public" # 1 WEEKHeader set Cache-Control "max-age=604800, public" # 3 HOURHeader set Cache-Control "max-age=10800" # NEVER CACHEHeader set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
Caching with mod_expires
ExpiresActive On ExpiresDefault A0 # 1 YEARExpiresDefault A29030400 # 1 WEEKExpiresDefault A604800 # 3 HOURExpiresDefault A10800"
Other Speed Tips
To truly speed up your site, you will want to implement a server-side caching technique. Or you can read more about caching and web cache.
Apache Caching Guide
This document supplements the mod_cache
, mod_disk_cache
, mod_mem_cache
, mod_file_cache
and htcacheclean reference documentation.
It describes how to use Apache's caching features to accelerate web and proxy serving, while avoiding common problems and misconfigurations.
htaccess time cheatsheet
# 300 5 MIN # 600 10 MIN # 900 15 MIN # 1800 30 MIN # 2700 45 MIN # 3600 1 HR # 7200 2 HR # 10800 3 HR # 14400 4 HR # 18000 5 HR # 36000 10 HR # 39600 11 HR # 43200 12 HR # 46800 13 HR # 50400 14 HR # 54000 15 HR # 86400 1 DAY # 172800 2 DAY # 259200 3 DAY # 345600 4 DAY # 432000 5 DAY # 518400 6 DAY # 604800 1 WEEK # 1209600 2 WEEK # 1814400 3 WEEK # 2419200 4 WEEK # 4838400 2 MONTH # 7257600 3 MONTH # 9676800 4 MONTH # 12096000 5 MONTH # 14515200 6 MONTH # 16934400 7 MONTH # 19353600 8 MONTH # 21772800 9 MONTH # 24192000 10 MONTH # 26611200 11 MONTH # 29030400 12 MONTH
« SEO Redirects without mod_rewriteApache Authentication in htaccess »
Comments