Class ResourcePreloadProcessor
- All Implemented Interfaces:
org.broadleafcommerce.presentation.dialect.BroadleafProcessor,org.broadleafcommerce.presentation.dialect.BroadleafTagReplacementProcessor
This is useful in combination with bundling where one bundle might depend on another and must wait for the other to finish before it can be added to the DOM. Since the script isn't immediately in the DOM, the browser doesn't download the resource until it's added to the DOM, increasing the time before the bundle can be used.
This processor adds preload link tags which tell the browser to preload (download) a resource even though it isn't yet in the DOM. Doing so decreases the latency when the script is ready to execute.
This processor has the ability to retrieve a bundle that has already been requested earlier in the template
looking it up with the bundle name. See ResourcesRequest for
more information. This helps with not having to duplicate the bundle information across the <blc:bundlepreload>
and <blc:bundle> tags.
The <bundlepreload> accepts all the parameters that ResourceBundleProcessor accepts, but will only ever
use them if they are relevant to generating the bundle.
- Author:
- Jacob Mitash
-
Field Summary
Fields inherited from class org.broadleafcommerce.common.web.processor.AbstractResourceProcessor
bundlingService, environment, resourcesRequestFields inherited from interface org.broadleafcommerce.presentation.dialect.BroadleafProcessor
DEFAULT_PRECEDENCE, DEFAULT_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.broadleafcommerce.presentation.model.BroadleafTemplateModelbuildModelBundled(List<String> attributeFiles, ResourceTagAttributes resourceTagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Builds the model that contains the bundled resources the tag should be replaced withprotected org.broadleafcommerce.presentation.model.BroadleafTemplateModelbuildModelUnbundled(List<String> attributeFiles, ResourceTagAttributes resourceTagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Builds the model that contains the unbundled resources the tag should be replaced withprotected org.broadleafcommerce.presentation.model.BroadleafTemplateElementbuildPreloadElement(String href, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Builds a preload link for the given pathprotected StringGets the "as" attribute for the link based off of the file namegetName()intgetPreloadAttributes(String href, String as) Builds a map of the attributes that should be put on the <link> tag.Methods inherited from class org.broadleafcommerce.common.web.processor.AbstractResourceProcessor
buildBundledFilesList, buildResourceTagAttributes, getBundleAppendText, getBundleCompleteEventJavaScript, getBundleEnabled, getBundlePath, getBundleUrl, getFullUnbundledFileName, getReplacementModel, getRequestedFileNames, postProcessUnbundledFileList, validateTagAttributesMethods inherited from class org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
getPrefix, replacementNeedsProcessing
-
Constructor Details
-
ResourcePreloadProcessor
public ResourcePreloadProcessor()
-
-
Method Details
-
getName
-
getPrecedence
public int getPrecedence()- Specified by:
getPrecedencein interfaceorg.broadleafcommerce.presentation.dialect.BroadleafProcessor- Overrides:
getPrecedencein classorg.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
-
buildModelBundled
protected org.broadleafcommerce.presentation.model.BroadleafTemplateModel buildModelBundled(List<String> attributeFiles, ResourceTagAttributes resourceTagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Description copied from class:AbstractResourceProcessorBuilds the model that contains the bundled resources the tag should be replaced with- Specified by:
buildModelBundledin classAbstractResourceProcessor- Parameters:
attributeFiles- list of files that are to be bundledresourceTagAttributes- the attributes of the original tag this processor replacescontext- the context of the original tag- Returns:
- model containing resources the tag should be replaced with
-
buildModelUnbundled
protected org.broadleafcommerce.presentation.model.BroadleafTemplateModel buildModelUnbundled(List<String> attributeFiles, ResourceTagAttributes resourceTagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Description copied from class:AbstractResourceProcessorBuilds the model that contains the unbundled resources the tag should be replaced with- Specified by:
buildModelUnbundledin classAbstractResourceProcessor- Parameters:
attributeFiles- list of files that are to be includedresourceTagAttributes- the attributes of the original tag this processor replacescontext- the context of the original tag- Returns:
- model containing resources the tag should be replaced with
-
buildPreloadElement
protected org.broadleafcommerce.presentation.model.BroadleafTemplateElement buildPreloadElement(String href, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) Builds a preload link for the given path- Parameters:
href- the path of the file to create the link withcontext- the context of the bundlepreload tag- Returns:
- a link element linking to the given resource
-
getPreloadAttributes
Builds a map of the attributes that should be put on the <link> tag.- Parameters:
href- the href of the resource to preloadas- the value the "as" attribute should have or null if it shouldn't be included- Returns:
- a map of attributes to place on the link tag
-
getAs
Gets the "as" attribute for the link based off of the file name- Parameters:
file- the name of the file- Returns:
- an appropriate "as" value or null if none was found
-