-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gavin Carr wrote:
> I do something similar to this but using attributes instead of methods in
> the autohandler:
>   % if (my $css = $m->request_comp->attr_if_exists('css')) {
>   <link rel="stylesheet" type="text/css" href="/css/<% $css %>" />
>   % }
> Slightly less flexible than yours, but lighter weight.
"Slightly" is quite inappropriate, "lighter" is OK. Why? Because you
miss almost all the flavor ("inheritance") by boiling it ;-)

> Another interesting trick is to setup an autohandler for the css files
NO! This is NOT "interesting", it's just like killing a mosquito using a
 shotgun. All you'll get is hurting yourself and all the others around.
Rules of thumb:
1) if it's static, DON'T use Mason to serve it;
2) if it's to be cached, then set caching tags appropriately;
3) if it's to be cached, then handle caching requests appropriately.

For all these rules, there's plenty of documentation/discussions on our
site (masonhq.com), mod_perl's (perl.apache.org) and the various mailing
lists around (mason, mod_perl, etc).

> This sets a Cache-Control header allowing client-side caching of your
> css files for an hour, since they're typically completely static.
If it's static, breaks 1). So it's not...

> <% $m->call_next %>
^ adds an extra "\n", instead you could use:
% $m->call_next;

>   <%init>
>   $r->header_out( 'Cache-Control', 'public,max-age=3600' );
>   my $stat = File::stat::stat $m->current_comp->source_file;
>   my $mtime = DateTime->from_epoch(epoch => $stat->mtime)->strftime("%a, %d 
> %b %Y %H:%M:%S GMT");
>   $r->header_out( 'Last-Modified', $mtime );
>   </%init>
Completely breaks 3), refer to $r->meets_conditions (Apache::File).
2) it's also broken even if barely taking into account just the facts
that you use header_out to set 'Last-Modified' and because you use
source_file's mtime.
For setting modification headers, use "set_last_modified", "set_etag"
AND "set_content_length". Also, using the "Vary" header properly will be
very helpful.
We settled it's not a static file, so using source_file's mtime is
wrong, as you don't use the resultant mtime composed from _all_ the
resources involved in generating the response.
Ah, and one more recommendation on this one: don't use DateTime for such
simple things, it's way too heavyweight for this purpose. Use
Apache::Util's parsedate/ht_time.

In the end, one "not so rule":
4) if caching friendliness it's too difficult to implement
appropriately, better don't implement it at all (and set $r->no_cache(1)
instead). ;-)

cheers
- --
Marius Feraru
-----BEGIN PGP SIGNATURE-----

iD8DBQFE1JMntZHp/AYZiNkRAmFAAJ9DmiMeul4FFQfoDBlRuFzcMnaObwCeOvet
h48ainNQKt+aS9QZHdrC458=
=Ziuo
-----END PGP SIGNATURE-----

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to