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