Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Forked from Fayozjon/htaccess-cache-config
Last active May 31, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zillionx/8d66d93993bc9781f26a607558629ef1 to your computer and use it in GitHub Desktop.
Save Zillionx/8d66d93993bc9781f26a607558629ef1 to your computer and use it in GitHub Desktop.
Enable and Disable Browser Caching with .htaccess
# Enable and Disable Browser Caching with .htaccess
## Enable Examples
### 1 MONTH for static assets
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
### 1 DAY for rss feeds and robots
<filesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=86400, public, must-revalidate"
</filesMatch>
### 4 HOURS for your real articles files
<filesMatch ".(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</filesMatch>
# Disable Example
<filesMatch ".(html|htm|js|css|jpg|png)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 08 Jan 1975 05:00:00 GMT"
</ifModule>
</filesMatch>
# Tips on Usage:
-- .htaccess configuration effects the directory contents in which it resides, as well as its subdirectories
-- .htaccess cannot be ready by browsers so it is secure for other operations.
-- creating the .htaccess file is best done on the server because most OS system settings will initially hide any file created that begins with a "."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment