Forum Moderators: phranque
# 5 Set Expires Headers
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Jan 2015 20:00:00 GMT"
</FilesMatch>
# 6 Set the cache-control max-age
# 1 year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 4 HOURS
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</FilesMatch>
#7 compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Various rewrite rules.
RewriteEngine on
# Rules to serve gzip-compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
#
# If the client accepts gzip and compressed CSS and JS files exist, internally rewrite and serve them with
# proper Content-Type headers and set the no-gzip variable to prevent double-encoding
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteCond $2->text/css ^css->(.+)$ [OR]
RewriteCond $2->text/javascript ^js->(.+)$
RewriteRule ^(.+\.(css|js))$ $1.gz [T=%1,E=no-gzip:1,L]
# compress these text/* MIME types
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/x-javascript text/xml application/xml application/xhtml+xml application/json
# server proper headers for precompressed css & javascript
<FilesMatch "\.(css|js)\.gz$">
# Serve correct encoding type.
Header append Content-Encoding gzip
# [Vary: Accept-Encoding] means a proxy server will cache both gzipped and uncompressed versions and serve the correct version based on the Accept-Encoding request header
# [Vary: User-Agent] means a proxy server will cache both gzipped and uncompressed versions and serve the correct version based on the User-Agent request header
# No Vary headers should be sent for MSIE-sourced requests
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary "Accept-Encoding"
Header append Vary "User-Agent"
BrowserMatch "MSIE" force-no-vary
</FilesMatch>
# server proper headers for uncompressed css & javascript
<FilesMatch "\.(css|js)$">
# [Vary: User-Agent] means a proxy server will cache both gzipped and uncompressed versions and serve the correct version based on the User-Agent request header
# No Vary headers should be sent for MSIE-sourced requests
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary "User-Agent"
BrowserMatch "MSIE" force-no-vary
</FilesMatch>
<ifModule mod_deflate.c>
<filesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
http://www.microsoft.com/search/tools/default.aspx
HTTP compression and conditional GET results
URL: http://example.net
HTTP status code: 304 Not Modified
HTTP conditional GET: enabled
HTTP compression: not enabled (HTTP compression can be enabled for non-304 URLs)
HTTP headers:
Connection: Keep-Alive
Keep-Alive: timeout=10, max=30
Vary: Accept-Encoding
Cache-Control: max-age=864000
Date: Fri, 28 Feb 2014 12:05:32 GMT
Expires: Mon, 10 Mar 2014 12:05:32 GMT
Server: Apache
HTTP conditional GET: enabled
HTTP compression: not enabled