Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp include vs. link tag for including CSS

 
Mike Spenser
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering as to the pros and cons associated with including an external CSS file for a page.

So far the main thing I come up with is that <link...> is client-side relative whereas the the <jsp:include ...> is server-side relative in terms of the CSS file's location.

Is there anything more substational than this? performance hits associated with the jsp:include?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link tag will allow the browser to cache the CSS file. I've never seen a CCS page included on the server side and would consider that a poor practice.
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done a combination of this before, using a <jsp:include> that would include a jsp, that renders the <link> tag for css.

the included file is a jsp, that contains the <link>tag to load either the external style sheet, or an inline style sheet, still within the <link> tag.

when i make a seperate file to put my css <link> tags, and other header type things that are common to all pages in my site, it saves me from having to cut-paste across all top level pages when something changes.
It is sort of like server side templating / organization of your conent. If you are used using the tiles framework, or similar, this jsp:include model fits nicely with the <tiles:insert> tags.

The motivation of using <jsp:include would render the contents of the seperate my_header.jsp is that the jsp becomes its own servlet, so the invocation is more like a function call, as opposed to if you <%@ include %> 'd it, then it would be verbatim inline with the calling servlet, which IMHO makes makes each file slighly unnecessarily larger and may at times (conspiracy theroy) take a little longer for the JSPs to compile (when you have hundreds)
I also prefer the <jsp:include over the <%@ include %> as I have noticed sometimes, on older (websphere) app servers do not always know to recompile a JSP when the <%@ include %>'d file is changed.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that the decision to use an include directive vs. an include action should be made depending on whether it makes sense for a separate (sub)request to be made to the resource or not --not to get around a container issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic