Speed Up Sites with htaccess Caching
Материал из RSU WiKi
There are 2 really easy and effective methods to speed up your entire website using apaches htaccess!
The first way is to use the Header Directive. from the mod_headers module
############################ # 300 5 MIN # 600 10 MIN # 900 15 MIN # 1800 30 MIN # 2700 45 MIN # # 3600 1 HR # 86400 24 HR # # 86400 1 DAY # 604800 7 DAY # # 604800 1 WEEK # # 2419200 1 MONTH # 29030400 12 MONTH ############################
Heres the first Header example
# MONTH <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$"> Header set Cache-Control "max-age=2592000" </FilesMatch> # WEEK <FilesMatch "\.(js|css|pdf|txt)$"> Header set Cache-Control "max-age=604800" </FilesMatch> # DAY <FilesMatch "\.(html|htm)$"> Header set Cache-Control "max-age=43200" </FilesMatch> # DONT CACHE <FilesMatch "\.(pl|php|cgi|spl)$"> Header set Cache-Control "max-age=0" </FilesMatch>
Another example using Headers
# 3 Months <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$"> Header set Cache-Control "max-age=7257600" </FilesMatch> # 7 Days <FilesMatch "\.(js|css|pdf|txt)$"> Header set Cache-Control "max-age=604800" </FilesMatch> # 10 minutes <FilesMatch "\.(html|htm)$"> Header set Cache-Control "max-age=600" </FilesMatch> # DONT CACHE <FilesMatch "\.(pl|php|cgi|spl)$"> Header unset Cache-Control Header unset Expires Header unset Last-Modified FileETag None Header unset Pragma </FilesMatch>
The second way is with the ExpiresByType Directive. from the mod_expires module
### turn on the Expires engine ExpiresActive On
### expires after a month in the client's cache ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType application/pdf A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType text/plain A2592000 ### expires after 4.8 hours ExpiresByType text/css A17200
Another example using mod_expires
ExpiresActive On ExpiresDefault A86400 ExpiresByType image/x-icon A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType text/css A2592000 ExpiresByType image/gif A604800 ExpiresByType image/png A604800 ExpiresByType image/jpeg A604800 ExpiresByType text/plain A604800 ExpiresByType application/x-shockwave-flash A604800 ExpiresByType video/x-flv A604800 ExpiresByType application/pdf A604800 ExpiresByType text/html A900
A good discussion about the Expires method can be found on Powweb or SitePoint

