Static cache Control by .htacces | Drupal 8

Static cache Control by .htacces

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

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 "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
      Header set Cache-Control "max-age=2592000, public, must-revalidate"
    <filesMatch "\.(ttf|woff)$">
      Header set Cache-Control "max-age=2592000, public, must-revalidate"
    # Disable caching for scripts and other dynamic files
    <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
      Header unset Cache-Control



Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.