Class CriticalStylesheet

All Implemented Interfaces:
PartialStateHolder, StateHolder, TransientStateHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener

public class CriticalStylesheet extends StylesheetFamily

The <o:criticalStylesheet> is a component based on the standard <h:outputStylesheet> which renders a <link rel="preload" as="style"> instead of <link rel="stylesheet"> and automatically changes the rel="preload" to rel="stylesheet" during window load event. Additionally, it will automatically be moved to the very top of the head.

Usage

Just use it the same way as a <h:outputStylesheet>, with a library and name.

 <o:criticalStylesheet library="yourlibrary" name="scripts/filename.js" />
 

You can even explicitly configure third-party stylesheet resources to be loaded this way, such as PrimeFaces stylesheets.

 <o:criticalStylesheet library="primefaces" name="components.css" />
 <o:criticalStylesheet library="primefaces" name="layout.css" />
 
Since:
4.5
Author:
Bauke Scholtz
See Also:
  • Field Details

    • COMPONENT_TYPE

      public static final String COMPONENT_TYPE
      The component type, which is "org.omnifaces.component.stylesheet.CriticalStylesheet".
      See Also:
  • Constructor Details

  • Method Details

    • processEvent

      public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
      Makes sure the critical style sheet gets added to top of head.
      Specified by:
      processEvent in interface ComponentSystemEventListener
      Overrides:
      processEvent in class UIComponent
      Throws:
      AbortProcessingException
    • getLibrary

      public String getLibrary()
      Returns the "library name" part of the resource identifier.
      Returns:
      The library name.
    • setLibrary

      public void setLibrary(String library)
      Sets the "library name" part of the resource identifier.
      Parameters:
      library - The library name.
    • getName

      public String getName()
      Returns the "resource name" part of the resource identifier.
      Returns:
      The resource name.
    • setName

      public void setName(String name)
      Sets the "resource name" part of the resource identifier.
      Parameters:
      name - The resource name.
    • getMedia

      public String getMedia()
      Returns the media that the stylesheet applies to.
      Returns:
      The media type.
    • setMedia

      public void setMedia(String media)
      Sets the media that the stylesheet applies to.
      Parameters:
      media - The media type.