Last active
July 10, 2020 07:08
-
-
Save VernonGrant/e4884f49ae82603cfefd0db144edfa26 to your computer and use it in GitHub Desktop.
Enable Broweser Caching and GZip to Apache2
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
# Place before all other things. | |
# Enable Compression | |
<IfModule mod_deflate.c> | |
AddOutputFilterByType DEFLATE application/javascript | |
AddOutputFilterByType DEFLATE application/rss+xml | |
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject | |
AddOutputFilterByType DEFLATE application/x-font | |
AddOutputFilterByType DEFLATE application/x-font-opentype | |
AddOutputFilterByType DEFLATE application/x-font-otf | |
AddOutputFilterByType DEFLATE application/x-font-truetype | |
AddOutputFilterByType DEFLATE application/x-font-ttf | |
AddOutputFilterByType DEFLATE application/x-javascript | |
AddOutputFilterByType DEFLATE application/xhtml+xml | |
AddOutputFilterByType DEFLATE application/xml | |
AddOutputFilterByType DEFLATE font/opentype | |
AddOutputFilterByType DEFLATE font/otf | |
AddOutputFilterByType DEFLATE font/ttf | |
AddOutputFilterByType DEFLATE image/svg+xml | |
AddOutputFilterByType DEFLATE image/x-icon | |
AddOutputFilterByType DEFLATE text/css | |
AddOutputFilterByType DEFLATE text/html | |
AddOutputFilterByType DEFLATE text/javascript | |
AddOutputFilterByType DEFLATE text/plain | |
AddOutputFilterByType DEFLATE text/xml | |
AddOutputFilterByType DEFLATE image/jpg | |
AddOutputFilterByType DEFLATE image/jpeg | |
AddOutputFilterByType DEFLATE image/png | |
AddOutputFilterByType DEFLATE image/gif | |
</IfModule> | |
# Leverage Browser Caching | |
<IfModule mod_expires.c> | |
ExpiresActive on | |
ExpiresByType image/jpg "access plus 60 days" | |
ExpiresByType image/png "access plus 60 days" | |
ExpiresByType image/gif "access plus 60 days" | |
ExpiresByType image/jpeg "access plus 60 days" | |
ExpiresByType text/css "access plus 1 days" | |
ExpiresByType image/x-icon "access plus 1 month" | |
ExpiresByType application/pdf "access plus 1 month" | |
ExpiresByType audio/x-wav "access plus 1 month" | |
ExpiresByType audio/mpeg "access plus 1 month" | |
ExpiresByType video/mpeg "access plus 1 month" | |
ExpiresByType video/mp4 "access plus 1 month" | |
ExpiresByType video/quicktime "access plus 1 month" | |
ExpiresByType video/x-ms-wmv "access plus 1 month" | |
ExpiresByType application/x-shockwave-flash "access 1 month" | |
ExpiresByType text/javascript "access plus 1 week" | |
ExpiresByType application/x-javascript "access plus 1 week" | |
ExpiresByType application/javascript "access plus 1 week" | |
</IfModule> | |
<IfModule mod_headers.c> | |
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$"> | |
Header set Cache-Control "max-age=2678400, public" | |
</filesmatch> | |
<filesmatch "\.(html|htm)$"> | |
Header set Cache-Control "max-age=7200, private, must-revalidate" | |
</filesmatch> | |
<filesmatch "\.(pdf)$"> | |
Header set Cache-Control "max-age=86400, public" | |
</filesmatch> | |
<filesmatch "\.(js)$"> | |
Header set Cache-Control "max-age=2678400, private" | |
</filesmatch> | |
</IfModule> |
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
# view installed apache2 mods | not required | |
ls /etc/apache2/mods-enabled | |
# enable deflate aka Gzip | |
a2enmod deflate | |
# enable expiring mod aka Browser caching | |
a2enmod expires | |
# headers mod | |
a2enmod headers | |
# restart apache2 | |
service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment