Static cache Control by .htacces | Drupal 8

Static cache Control by .htacces

Submitted by editor on Mon, 03/20/2017 - 20:31
Question

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>

 

Tags

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.