tags:

views:

53

answers:

3

Is there a better way to aggregate several css files ( based on what a give page requires ) than including them in a jsp file with c:if tags?

The top of the file (sitting outside of web-inf dir, alongside images files and such)

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/css" %>

... followed by <%@include file="some.css" %> as needed. It works, it's simple, I'm just wondering if it could be done better.

+1  A: 

Is there any reason why you can't just include the CSS pages with normal HTML links, so that they can be cached?

<link rel="stylesheet" href="some.css" type="text/css" media="screen" />
<link rel="stylesheet" href="some2.css" type="text/css" media="screen" />

That way the browser can cache the file, and requests will only be made once for all the pages that use it. Then you could just have each page specify the links that it needs.

Kaleb Brasee
just want to send over a single css file that's fairly condensed and page specific.
vector
+1  A: 

How about

<link rel="stylesheet" type="text/css" href="${pageSpecificCssFileName}.css">

wherein you define ${pageSpecificCssFileName} in page controller?

BalusC
+2  A: 

If you were kind, your CSS request would follow some kind of aggregation pattern.

<link rel="stylesheet" type="text/css" href="core.css?part1&part2&part3">

And then, your result would be kind enough to set the caching headers properly, the ETag, and honor the "If-Modified-Since" header (perhaps based on the latest change date of the files you decide to include).

Will Hartung
... hm, I'll look into this one! Thanks.
vector