Apache Example

If your server uses Apache and compression is not already enabled, a server admin can review a standard setup like this:

apache
apache
1<IfModule mod_deflate.c>
2 AddOutputFilterByType DEFLATE text/plain
3 AddOutputFilterByType DEFLATE text/html
4 AddOutputFilterByType DEFLATE text/css
5 AddOutputFilterByType DEFLATE text/javascript
6 AddOutputFilterByType DEFLATE application/javascript
7 AddOutputFilterByType DEFLATE application/x-javascript
8 AddOutputFilterByType DEFLATE application/json
9 AddOutputFilterByType DEFLATE application/xml
10 AddOutputFilterByType DEFLATE image/svg+xml
11</IfModule>
12
13<IfModule mod_expires.c>
14 ExpiresActive On
15 ExpiresByType text/css "access plus 1 month"
16 ExpiresByType application/javascript "access plus 1 month"
17 ExpiresByType image/jpeg "access plus 1 year"
18 ExpiresByType image/png "access plus 1 year"
19 ExpiresByType image/webp "access plus 1 year"
20 ExpiresByType image/svg+xml "access plus 1 year"
21 ExpiresByType font/woff2 "access plus 1 year"
22</IfModule>
23
24<IfModule mod_headers.c>
25 <FilesMatch "\.(css|js|jpg|jpeg|png|webp|svg|woff2)$">
26 Header set Cache-Control "public, max-age=2592000"
27 </FilesMatch>
28</IfModule>

Notes:

  • Some hosts already set these rules globally.

  • Some managed hosts block custom .htaccess rules.

  • If your site already has caching rules, merge carefully rather than pasting duplicate blocks.

Continue reading