Files and Cache Expiration
For Apache to send along
Expireswith your staticly served files, you will need to make sure that
mod_expireshas been installed on your server. It is fairly standard and none of my servers I checked (that includes OS X’s Apache installation), didn’t have
mod_expiredon the system. You may have to search through your
httpd.conffile and uncomment (remove the pound-signs) from the following lines, however:
#LoadModule expires_module libexec/httpd/mod_expires.so
Once you’ve uncommented these lines, you should restart Apache. It differs depending on your system, but generally you can issue the following command:
sudo apachectl restart
If that didn’t work, look through your system’s manual or documentation for more information on how to restart Apache.
Once that’s done, go to the directory where your statically served files are contained and add or edit the
.htaccess file in that directory. Add the following lines:
<ifmodule mod_expires.c> <filesmatch "\.(jpg|gif|png|css|js)$"> ExpiresActive on ExpiresDefault "access plus 1 year" </filesmatch> </ifmodule>
The following bit:
jpg|gif|png|css|js specifies the file types you’d like to target and this other bit:
ExpiresDefault "access plus 1 year" specifies how long into the future you’d like to set the expiration date. In this case it’s one year into the future.