[Catalyst] Best practice - serving static content

Will Hawes info at whawes.co.uk
Wed Jun 29 18:59:37 CEST 2005


While playing with the ServerDB example version 1.01, I noticed that a template is added to the stash in the end() method in ServerDB.pm:

$c->stash->{template} = "server/list.xhtml";

Curious as to why this is needed, I commented it out and found that I started getting errors similar like this under the test server:

Couldn't render template "file error - static: not found"

I checked Catalyst::Plugin::Static (version 0.07) and found that it only fills $c->res if static content has been modified since it was last requested. If not, it returns status 304, clears the response headers and exits. 

The ServerDB app (and Hops, and most of example code I have seen) all do something like this in the end() method of the main controller:

$c->forward( 'ServerDB::V::TT' ) unless $c->res->output;

Static content doesn't change all that often by definition, so $c->res->output will usually be empty when it is requested. Any app using the above technique will therefore incur unnecessary overhead because $c->forward will still be called once the static content has been served.

wh




More information about the Catalyst mailing list