Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF2 Static Resource Management -- Combined, Compressed
    primarykey
    data
    text
    <p>Is anyone aware of a method to dynamically combine/minify all the h:outputStylesheet resources and then combine/minify all h:outputScript resources in the render phase? The comined/minified resource would probably need to be cached with a key based on the combined resource String or something to avoid excessive processing.</p> <p>If this feature doesn't exist I'd like to work on it. Does anyone have ideas on the best way to implement something like this. A Servlet filter would work I suppose but the filter would have to do more work than necessary -- basically examining the whole rendered output and replacing matches. Implementing something in the render phase seems like it would work better as all of the static resources are available without having to parse the entire output. </p> <p>Thanks for any suggestions!</p> <p><strong>Edit:</strong> <em>To show that I'm not lazy and will really work on this with some guidance, here is a stub that captures Script Resources name/library and then removes them from the view. As you can see I have some questions about what to do next ... should I make http requests and get the resources to combine, then combine them and save them to the resource cache?</em></p> <pre><code>package com.davemaple.jsf.listener; import java.util.ArrayList; import java.util.List; import javax.faces.component.UIComponent; import javax.faces.component.UIOutput; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.PhaseEvent; import javax.faces.event.PhaseId; import javax.faces.event.PhaseListener; import javax.faces.event.PreRenderViewEvent; import javax.faces.event.SystemEvent; import javax.faces.event.SystemEventListener; import org.apache.log4j.Logger; /** * A Listener that combines CSS/Javascript Resources * * @author David Maple&lt;d@davemaple.com&gt; * */ public class ResourceComboListener implements PhaseListener, SystemEventListener { private static final long serialVersionUID = -8430945481069344353L; private static final Logger LOGGER = Logger.getLogger(ResourceComboListener.class); @Override public PhaseId getPhaseId() { return PhaseId.RESTORE_VIEW; } /* * (non-Javadoc) * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent) */ public void afterPhase(PhaseEvent event) { FacesContext.getCurrentInstance().getViewRoot().subscribeToViewEvent(PreRenderViewEvent.class, this); } /* * (non-Javadoc) * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent) */ public void beforePhase(PhaseEvent event) { //nothing here } /* * (non-Javadoc) * @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object) */ public boolean isListenerForSource(Object source) { return (source instanceof UIViewRoot); } /* * (non-Javadoc) * @see javax.faces.event.SystemEventListener#processEvent(javax.faces.event.SystemEvent) */ public void processEvent(SystemEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot viewRoot = context.getViewRoot(); List&lt;UIComponent&gt; scriptsToRemove = new ArrayList&lt;UIComponent&gt;(); if (!context.isPostback()) { for (UIComponent component : viewRoot.getComponentResources(context, "head")) { if (component.getClass().equals(UIOutput.class)) { UIOutput uiOutput = (UIOutput) component; if (uiOutput.getRendererType().equals("javax.faces.resource.Script")) { String library = uiOutput.getAttributes().get("library").toString(); String name = uiOutput.getAttributes().get("name").toString(); // make https requests to get the resources? // combine then and save to resource cache? // insert new UIOutput script? scriptsToRemove.add(component); } } } for (UIComponent component : scriptsToRemove) { viewRoot.getComponentResources(context, "head").remove(component); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload