Class ResourcePreloadProcessor

java.lang.Object
org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
org.broadleafcommerce.common.web.processor.AbstractResourceProcessor
org.broadleafcommerce.common.web.processor.ResourcePreloadProcessor
All Implemented Interfaces:
org.broadleafcommerce.presentation.dialect.BroadleafProcessor, org.broadleafcommerce.presentation.dialect.BroadleafTagReplacementProcessor

@Component("blResourcePreloadProcessor") @ConditionalOnTemplating public class ResourcePreloadProcessor extends AbstractResourceProcessor
Adds <link> tags to the model that preload resources.

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
  • Constructor Details

    • ResourcePreloadProcessor

      public ResourcePreloadProcessor()
  • Method Details

    • getName

      public String getName()
    • getPrecedence

      public int getPrecedence()
      Specified by:
      getPrecedence in interface org.broadleafcommerce.presentation.dialect.BroadleafProcessor
      Overrides:
      getPrecedence in class org.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: AbstractResourceProcessor
      Builds the model that contains the bundled resources the tag should be replaced with
      Specified by:
      buildModelBundled in class AbstractResourceProcessor
      Parameters:
      attributeFiles - list of files that are to be bundled
      resourceTagAttributes - the attributes of the original tag this processor replaces
      context - 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: AbstractResourceProcessor
      Builds the model that contains the unbundled resources the tag should be replaced with
      Specified by:
      buildModelUnbundled in class AbstractResourceProcessor
      Parameters:
      attributeFiles - list of files that are to be included
      resourceTagAttributes - the attributes of the original tag this processor replaces
      context - 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 with
      context - the context of the bundlepreload tag
      Returns:
      a link element linking to the given resource
    • getPreloadAttributes

      protected Map<String,String> getPreloadAttributes(String href, String as)
      Builds a map of the attributes that should be put on the <link> tag.
      Parameters:
      href - the href of the resource to preload
      as - 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

      protected String getAs(String file)
      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