How to enable static cache Control using .htacces ?
Static cache Control by .htacces
If not already done, you must enable apache headers (mod_headers.c) module
Check module is enabled or not:
ls /etc/apache2/mods-enabled/
Eneble module:
sudo a2enmod headers
sudo service apache2 restart
Add Cache controle to .htaccess file:exit
#Static cache
<IfModule mod_headers.c>
#2592000 = 1Year, 86400=24h
#CSS and JS files
<filesMatch "\.(js|css)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
#Images
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
</filesMatch>
#Fonts
<filesMatch "\.(ttf|woff)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
</filesMatch>
# Disable caching for scripts and other dynamic files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>
Comments