Last active
June 2, 2020 18:28
-
-
Save quickstep25/58fbc240b2878b495af6 to your computer and use it in GitHub Desktop.
Enable and Disable Browser Caching with .htaccess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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