- java.lang.Object
- 
- jakarta.faces.component.UIComponent
- 
- jakarta.faces.component.UIComponentBase
- 
- org.omnifaces.component.script.ScriptFamily
- 
- org.omnifaces.component.script.DeferredScript
 
 
 
 
- 
- All Implemented Interfaces:
- PartialStateHolder,- StateHolder,- TransientStateHolder,- ComponentSystemEventListener,- FacesListener,- SystemEventListenerHolder,- EventListener
 
 public class DeferredScript extends ScriptFamily The <o:deferredScript>is a component based on the standard<h:outputScript>which defers the loading of the given script resource to the window load event. In other words, the given script resource is only loaded when the window is really finished with loading. So, the enduser can start working with the webpage without waiting for the additional scripts to be loaded. Usually, it are those kind of scripts which are just for progressive enhancement and thus not essential for the functioning of the webpage.This will give bonus points with among others the Google PageSpeed tool, on the contrary to placing the script at bottom of body, or using defer="true"or evenasync="true".Since 2.4 this will render the crossoriginattribute with a value ofanonymous. Since 3.13 this will also render theintegrityattribute with a base64 encoded sha384 hash as SRI, see also MDN.UsageJust use it the same way as a <h:outputScript>, with alibraryandname.<o:deferredScript library="yourlibrary" name="scripts/filename.js" /> You can use the optional onbegin,onsuccessandonerrorattributes to declare JavaScript code which needs to be executed respectively right before the script is loaded, right after the script is successfully loaded, and/or when the script loading failed.- Since:
- 1.8
- Author:
- Bauke Scholtz
- See Also:
- DeferredScriptRenderer,- ScriptFamily
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringCOMPONENT_TYPEThe component type, which is "org.omnifaces.component.script.DeferredScript".- 
Fields inherited from class org.omnifaces.component.script.ScriptFamilyCOMPONENT_FAMILY
 - 
Fields inherited from class jakarta.faces.component.UIComponentATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY
 
- 
 - 
Constructor SummaryConstructors Constructor Description DeferredScript()Construct a newDeferredScriptcomponent whereby the renderer type is set toDeferredScriptRenderer.RENDERER_TYPE.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprocessEvent(ComponentSystemEvent event)Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent).- 
Methods inherited from class org.omnifaces.component.script.ScriptFamilyencodeBegin, encodeEnd, getFamily, getRendersChildren, moveToBody
 - 
Methods inherited from class jakarta.faces.component.UIComponentBaseaddClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
 - 
Methods inherited from class jakarta.faces.component.UIComponentencodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
 
- 
 
- 
- 
- 
Field Detail- 
COMPONENT_TYPEpublic static final String COMPONENT_TYPE The component type, which is "org.omnifaces.component.script.DeferredScript".- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
DeferredScriptpublic DeferredScript() Construct a newDeferredScriptcomponent whereby the renderer type is set toDeferredScriptRenderer.RENDERER_TYPE.
 
- 
 - 
Method Detail- 
processEventpublic void processEvent(ComponentSystemEvent event) Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent). If successfully moved, then set the script resource as rendered, so that Faces won't auto-include it.- Specified by:
- processEventin interface- ComponentSystemEventListener
- Overrides:
- processEventin class- UIComponent
 
 
- 
 
-