On Tue, Aug 01, 2006 at 01:35:30PM -0700, Ken Woodruff wrote:
> As an aside to this topic I find the it handy to include a "css"  
> method call in the autohandler to enable page specific styles and/or  
> stylesheet links when needed (since they must appear in the head, but  
> the <head> is generated by the autohandler).  This helps cut down on  
> clogging the main stylesheet with lots of page specific nits.
> 
> In the autohandler:
> 
> <html>
>      <head>
>          <title><& SELF:title &></title>
>          <link rel="stylesheet" type="text/css" href="/css/default.css">
>          <& SELF:css &>
>      </head>
>      <body>
> % $m->call_next;
>      </body>
> </html>
> <%method css></%method>

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.

Another interesting trick is to setup an autohandler for the css files
like this:

  <% $m->call_next %>
  <%init>
  # Allow proxy/client caching
  # NB: to make caching work this file MUST be static for a given filename - 
  #   per-browser variants etc. are okay, but they must have different 
filenames!
  $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>
  <%flags>
  inherit => undef
  </%flags>

This sets a Cache-Control header allowing client-side caching of your css files
for an hour, since they're typically completely static. If you watch your access
logs you'll see the browser only requests the css once per hour. I use exactly 
the
same autohandler for javascript files too.

Cheers,
Gavin

--
Gavin Carr
Open Fusion - Open Source Business Solutions [ Linux - Perl - Apache ]
http://www.openfusion.com.au
- Fashion is a variable, but style is a constant - Programming Perl

-------------------------------------------------------------------------
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