Created
June 21, 2016 13:28
-
-
Save savelee/55b79c29d841c1f1e2131387f6732d4f to your computer and use it in GitHub Desktop.
Server Caching Apache
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
How to enable server caching | |
Install the following 2 mods: | |
$ sudo a2enmod expires | |
$ sudo a2enmod headers | |
Add this to the .htaccess | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresDefault "access plus 1 seconds" | |
ExpiresByType text/html "access plus 1 seconds" | |
ExpiresByType image/gif "access plus 12 months" | |
ExpiresByType image/jpeg "access plus 12 months" | |
ExpiresByType image/png "access plus 12 months" | |
ExpiresByType text/css "access plus 4 weeks" | |
ExpiresByType text/javascript "access plus 4 weeks" | |
ExpiresByType application/x-javascript "access plus 4 weeks" | |
ExpiresByType text/xml "access plus 12 months" | |
ExpiresByType image/ico "access plus 1 year" | |
</IfModule> | |
# END WordPress | |
# 1 YEAR | |
<FilesMatch "\.(flv|ico|jpg|xml|txt|png|jpeg|gif|swf|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> | |
Header set Cache-Control "max-age=31536000, public" | |
</FilesMatch> | |
# 2 WEEKS | |
<FilesMatch "\.(js|css)$"> | |
Header set Cache-Control "max-age=1209600" | |
</FilesMatch> | |
# NEVER CACHE - notice the extra directives | |
<FilesMatch "\.(html|htm|php)$"> | |
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate" | |
</FilesMatch> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment