Cache expiration on static images and content with .htaccess

One of main thing for all web sites is content caching to improve site performance. Here are few examples how You can achieve this. Set this cache expiration example, which I am using on my content delivery network (CDN) server

<FilesMatch ".(jpg|png|gif)$">
ExpiresDefault A0
Header set Cache-Control "max-age=0,  no-cache, must-revalidate"

Which mean, that expiration date is in access moment and set headers to 0 values. As You can see, here You can add more filetypes for static content

.htaccess cache expiration code

This example can also speed-up Your webpage just with few lines of code by setting longer expiration time:

ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000

Where A is access time and 2592000=60*60*24*30 or one month.

You can tray this example,which I am using on my content delivery network (CDN) server

Leave a Reply

Your email address will not be published. Required fields are marked *