[Catalyst] Re: Best practice - serving static content
Andy Grundman
andy at hybridized.org
Wed Jun 29 23:26:51 CEST 2005
Will Hawes wrote:
> 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;
You're right, that template default shouldn't really be there. I
believe the correct code should be something like this:
sub end : Global {
my ($self, $c) = @_;
$c->forward('MyApp::V::TT')
unless ( $c->res->output || !$c->stash->{template} );
# for easy debugging
die if $c->req->params->{die} && $c->debug;
}
This way static content will not bother with forwarding to the view,
improving performance somewhat.
-Andy
More information about the Catalyst
mailing list