[Catalyst] Serve blob files into src="" type tags

Bill Moseley moseley at hank.org
Sun Mar 12 15:36:10 CET 2006


On Sun, Mar 12, 2006 at 01:29:18PM +0000, Matt S Trout wrote:
> I've ended up making the same call on a couple of occasions, and it's worked 
> out pretty well. *but* there's one thing you really have to take account of - 
> make sure the code the serves the BLOBs understands a HEAD request and sends 
> an appropriate Last-Modified-Time (and pref. can deal with If-Modified-Since 
> and friends as well). That way when you need to scale you can stick a reverse 
> proxy in front of the app, and presto, the files *are* being served off disk - 
> out of the proxy cache :)

There's also PageCache plugin as one more thing to look at (although
not a replacement for proxy).

I do this for my 304 checks:

    my $res = $c->res;

    $res->headers->header( 'Cache-Control' => 'max-age=86400' );
    $res->headers->expires( time + 86400 );

    if ( ($c->req->headers->if_modified_since || 0 ) == $image->{last_modified} ) {
        $res->status(304);
        return;
    }

    $res->body( $image->{image} );
    $res->content_type( $image->{mime} || 'image/jpeg' );
    $res->headers->last_modified( $image->{last_modified} );


IIRC, last-modified doesn't go in a 304 response (the client already
knows it, of course).

-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list