Popular Posts

mod_expires in htaccess


Introduction:

Mod_expires is an Apache Web server module installed on all of our Linux hosting accounts by default and supports all mod_expires functionality.

Because we do not enable mod_expires at the global level, you need to enable it in your .htaccess file. You can enable it on a per-directory basis and it applies recursively.

When visiting a website, the website will cache in your browser. This cache can be controlled by configuring your Cache-Control HTTP headers for your website This is done by adding mod_expires in the .htaccess file of your server.

Code for mode_expires:

<IfModule mod_expires.c>
  ExpiresActive on
#
# Perhaps better to whitelist expires rules? Perhaps.
#
  ExpiresDefault                          "access plus 1 year"
#
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
#
  ExpiresByType text/cache-manifest       "access plus 0 seconds"
#
# Your document html
#
ExpiresByType text/html                 "access plus 0 seconds"
#
# Data
#
  ExpiresByType text/xml                  "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType application/json          "access plus 0 seconds"
#
# Feed
#
  ExpiresByType application/rss+xml       "access plus 1 hour"
  ExpiresByType application/atom+xml      "access plus 1 hour"
#
# Favicon (cannot be renamed)
#
  ExpiresByType image/x-icon              "access plus 1 year"
#
# Media: images, video, audio
#
  ExpiresByType image/gif                 "access plus 1 year"
  ExpiresByType image/png                 "access plus 1 year"
  ExpiresByType image/jpeg                "access plus 1 year"
  ExpiresByType image/jpg                 "access plus 1 year"
  ExpiresByType video/ogg                 "access plus 1 year"
  ExpiresByType audio/ogg                 "access plus 1 year"
  ExpiresByType video/mp4                 "access plus 1 year"
  ExpiresByType video/webm                "access plus 1 year"
#
# HTC files  (css3pie)
#
  ExpiresByType text/x-component          "access plus 1 month"
#
# Webfonts
#
  ExpiresByType application/x-font-ttf    "access plus 1 year"
  ExpiresByType font/opentype             "access plus 1 year"
  ExpiresByType application/x-font-woff   "access plus 1 year"
  ExpiresByType image/svg+xml             "access plus 1 year"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
#
# CSS and JavaScript
#
  ExpiresByType text/css                  "access plus 1 year"
  ExpiresByType application/javascript    "access plus 1 year"
</IfModule>
mod_expires in htaccess mod_expires in htaccess Reviewed by Snehal Vasava on May 22, 2018 Rating: 5

No comments:

Breaking

Powered by Blogger.