Caching using mod_expires and mod_headers
With all growing traffic to websites, heavy graphic files and multiple simultaneous visitors, sometimes you need to use every tool you can, to optimize your site loading and achieve bets performance. One of the thing you must consider then is caching.
Main advantage of caching is that there is no need to download file again if it was already downloaded once by browser. And disadvantage of course it that, if file was changed on server, changes won't appear to end user, while cache won't expire. So you must consider which files to cache and for how long time period.
# Turn on Expires and set default to 0 ExpiresActive On ExpiresDefault A0 # Set up caching on media files for 1 year (consider it forever) <FilesMatch ".(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> ExpiresDefault A29030400 Header append Cache-Control "public" </FilesMatch> # Set up caching on media files for 1 week <FilesMatch ".(gif|jpg|jpeg|png|swf)$"> ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> # Set up 2 Hour caching on commonly updated files <FilesMatch ".(xml|txt|html|js|css)$"> ExpiresDefault A7200 Header append Cache-Control "proxy-revalidate" </FilesMatch> # Force no caching for dynamic files <FilesMatch ".(php|cgi|pl|htm)$"> ExpiresActive Off Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" Header set Pragma "no-cache" </FilesMatch>
You may also be interested in:
Powered by BlogAlike.com