Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Static cache Control by .htacces

By editor , 20 March, 2017
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

  • Linux
  • Server

Comments

Plain text

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

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer