Compressing and Caching for websites

Here is what I was looking for when I started learning about websites, compression and caching…

I’ve only ever used Linux servers so I only know about using htaccess

For caching and compresssing we get the modules: mod_deflate and mod_cache (if I remember right) and heres a generic sample of what I’ve used:

######### DEFLATE
Addtype font/opentype .eot
Addtype font/opentype .otf
Addtype font/truetype .ttf
Addtype font/woff .woff
AddOutputFilterByType DEFLATE image/gif image/png image/jpeg image/jpg image/ico application/javascript text/css text/html text/xml text/plain font/woff font/embedded-opentype font/opentype font/truetype
######### Cache-Control
# 1 min = 60
# 5 min = 300
# 1 Hour  = 3600 ( must-revalidate)
# 1 Day   = 43200
# 3 Day   = 129600
# 1 Week  = 604800
# 1 Month = 2592000
# 6 Month = 15552000
# 1 Year  = 29030400
# or
######### expires
ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault “access plus 1 year”

# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest “access plus 0 seconds”

# Your document html
ExpiresByType text/html “access plus 3 minutes”

# Data
ExpiresByType text/xml “access plus 0 seconds”
ExpiresByType application/xml “access plus 0 seconds”
ExpiresByType application/json “access plus 0 seconds”

# RSS feed
ExpiresByType application/rss+xml “access plus 1 hour”

# Favicon (cannot be renamed)
ExpiresByType image/x-icon “access plus 1 week”

# Media: images, video, audio
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/jpg “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType video/ogg “access plus 1 month”
ExpiresByType audio/ogg “access plus 1 month”
ExpiresByType video/mp4 “access plus 1 month”
ExpiresByType video/webm “access plus 1 month”

# HTC files  (css3pie)
ExpiresByType text/x-component “access plus 1 month”

# Webfonts
ExpiresByType font/truetype “access plus 1 month”
ExpiresByType font/opentype “access plus 1 month”
ExpiresByType application/x-font-woff “access plus 1 month”
ExpiresByType image/svg+xml “access plus 1 month”
ExpiresByType application/vnd.ms-fontobject “access plus 1 month”

# CSS and JavaScript
ExpiresByType text/css “access plus 1 week”
ExpiresByType application/javascript “access plus 1 week”
ExpiresByType text/javascript “access plus 1 week”
########## X-ROBOTS for files
<FilesMatch “\.(html|txt|php)$”>
Header set X-Robots-Tag “noarchive”
</FilesMatch>
<FilesMatch “\.(epub|pdf|shtml)$”>
Header set X-Robots-Tag “noindex,nofollow”
</FilesMatch>
########## ENCODING
<FilesMatch “\.(js|css|xml)$”>
Header append Vary Accept-Encoding
</FilesMatch>

Be careful… Test individual lines and check it using redbot