How to Implement a Caching Scheme with htaccess file

You can cache the static files and improve your website’s performance. File caching is another famous approach in optimizing website loading time. Search engine will rank your website higher if your website response time is faster. Almost all website especially wordpress websites are caching their static files:

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$"> 
Header set Cache-Control "max-age=2592000"
# year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified

#2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"

<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"

Disable caching for certain file type

Well, in the other hand, you can disable caching for certain file type.

# explicitly disable caching for scripts and other dynamic files
 <FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$">
 Header unset Cache-Control

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.