*this
home about contact feed
projects
vagra vaBlo
categories
C++(7) Solaris(4) tntnet(3) vi(3) Linux(2) DeleGate(2) Postgres(2) proxy(2) cxxtools(1) regex(1) readline(1) dtrace(1) gcc(1) MeeGo(1) ssh(1) firefox(1)

setting cacheControl headers for static content in tntnet

cacheControl for tntnet

tntnet contains an static component, that allows you to serve static content directly from your filesystem using send-file. But the static component doesn't add Expire or cacheControl headers, thus clients or proxys will ask every time if the file as changed. For files like your CSS what will likely be loaded for every site but changes only seldom, this will significantly increase the number of unnecessary requests to tntnet.

Luckily tntnet allows you to pass a requests to more than one component, thus you can benefit from the easiness of the static componend and add additional haeders.

<%pre>
  #include <tnt/httpheader.h>
</%pre>
<%cpp>
  reply.setHeader(tnt::httpheader::cacheControl, "public, max-age=86400");
  return DECLINED;
</%cpp>

The return DECLINED will cause tntnet to keep whatever content the component added to reply and then pass the request to the next componend on the UrlMap.

MapUrl  ^/static/(.*)   expire@vtoc
MapUrl  ^/static/(.*)   static@tntnet static/$1
Write comment