A solution I've currently implemented is a RenderFilter which writes the entire JS and CSS resource pool to the head if the pool is not already written. This is somewhat sub optimal as detecting pending head elements is not something that I've found can be done in a platform-independent manner. However, deciding what to do with redundant head elements is completely up to platform delegation, as JSR-286 does not dictate what should be done in this case.
Through use of eXo's PortalRequestContext, it's possible to obtain the list of pending head elements. By adding a meta element to identify the resource pool, the RenderFilter can then decide if the pool needs to be written or if it already has been written.
Here is the basic detection logic:
boolean addHeaderElements = true;
if (Util.getPortalRequestContext() != null && Util.getPortalRequestContext().getExtraMarkupHeaders() != null)
{
for (Element markupHeaderElement : Util.getPortalRequestContext().getExtraMarkupHeaders())
{
if (markupHeaderElement.getTagName().equalsIgnoreCase("meta") &&
markupHeaderElement.getAttribute("name") != null &&
markupHeaderElement.getAttribute("name").equalsIgnoreCase("project-name"))
{
addHeaderElements = false;
break;
}
}
}
This could also be written to operate on a file basis, but my portlets' resource pool is commonly shared to the point that an all-or-nothing approach can be used.