[thelist] Server page includes: javascript and CSS belong in the header!

Hassan Schroeder hassan.schroeder at gmail.com
Fri Feb 16 18:24:17 CST 2007


On 2/16/07, Will Budreau <Will.Budreau at entrust.com> wrote:
> In our codebase, we use JSP includes and Tiles to nest JSP fragments.

> I can think of three solutions

Solution 0 would be to not use the inherently fragmented Tiles
approach :-) but ...

> 1) Specify a way for an included file/tile to add a CSS or Javascript file to the html <head>

> 2) Each JSP documents what supporting static files it needs added to the head.

"documents"?

How are you building these pages? At the point you're delivering the
actual View (big V, in MVC), all the content should be known.

Personally I use a complete template, generate a Content object in
the assembly pipeline and pass that as a request attribute to the
template. Then it's just (simplified!)
<head>
<title>${content.title}</title>
<!-- common stuff first -->
<!-- followed by page-unique stuff, e.g. -->
<style type="text/css">
${content.css}
</style>
<script type="text/javascript">
${content.js}
</script>
</head>
<body>
${content.main}

..and so on.

But you could probably adapt that to work with Tiles...

FWIW!
-- 
Hassan Schroeder ------------------------ hassan.schroeder at gmail.com



More information about the thelist mailing list