While optimizing the cache performance using a reverse proxy in Apache
I noticed some missing headers on responses which prevent webclient-
caching. I know that the current advice is to let Apache serve the
static files, but in my case the frontend Apache server is on another
server/VLAN /subnet for security reasons.
The Content-type header on static files like .js .css and pictures is
missing. This prevents adding automatic expire heading using the
Apache module mod_expire
I solved the problem using the apache settings below. I'm not saying
the setup below is optimal, still working on it, but it for now it
seems to improve local caching in IE, Chrome and FF and at least
quiets down YFlow and Chrome Audit reports on 'unable to cache'. My
next step is to switch on mod_cache (disk or mem) on Apache.
Is there any reason for Web2py / Rocket *not* to add Content-type?
In any case I'm volunteering to document this setup in the Web2py Book
or on a slice if you think its usefull.
Nico
-----
# Note that ProxyMatch should be used when proxying instead of
<FilesMatch>
<ProxyMatch "\.css$>
Header set Content-type: "text/css"
</ProxyMatch>
<ProxyMatch "\.js$>
Header set Content-type: "text/javascript"
</ProxyMatch>
<ProxyMatch "\.ico$>
Header set Content-type: "image/vnd.microsoft.icon"
</ProxyMatch>
# Enable gzipping using mod_deflate
AddOutputFilterByType DEFLATE text/plain text/xml text/css
text/javascript application/javascript
# Add calculated expire header using mod_expire
ExpiresActive On
ExpiresByType image/ico A15552000
ExpiresByType image/vnd.microsoft.icon A15552000
ExpiresByType image/gif A31622400
ExpiresByType image/png A31622400
ExpiresByType image/jpg A31622400
ExpiresByType image/jpeg A31622400
ExpiresByType text/javascript A31622400
ExpiresByType application/javascript A31622400
ExpiresByType text/css A31622400
# > one year
<ProxyMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|ttf|
eot)$">
Header set Cache-Control "max-age=31622400, public"
</ProxyMatch>