@Component(value="blResourceBundleProcessor")
@ConditionalOnTemplating
public class ResourceBundleProcessor
extends org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
Works with the blc:bundle tag.
This processor does not do the actual bundling. It merely changes the URL which causes the other bundling components to be invoked through the normal static resource handling processes.
This processor relies bundle.enabled. If this property is false (typical for dev) then the list of
resources will be output as individual SCRIPT or LINK elements for each JavaScript or CSS file respectively.
To use this processor, supply a name, mapping prefix, and list of files.
<blc:bundle name="lib.js"
mapping-prefix="/js/"
files="plugins.js,
libs/jquery.MetaData.js,
libs/jquery.rating.pack.js,
libs/jquery.dotdotdot-1.5.1.js" />
With bundling enabled this will turn into:
<script type="text/javascript" src="/js/lib-blbundle12345.js" />
Where the -blbundle12345 is used by the BundleUrlResourceResolver to determine the actual bundle name.
With bundling disabled this turns into:
<script type="text/javascript" src="/js/plugins.js" />
<script type="text/javascript" src="/js/jquery.MetaData.js" />
<script type="text/javascript" src="/js/jquery.rating.pack.js.js" />
<script type="text/javascript" src="/js/jquery.dotdotdot-1.5.1.js" />
This processor also supports producing the 'async' and 'defer' attributes for Javascript files. For instance:
<blc:bundle name="lib.js"
async="true"
defer="true"
mapping-prefix="/js/"
files="plugins.js,
libs/jquery.MetaData.js,
libs/jquery.rating.pack.js,
libs/jquery.dotdotdot-1.5.1.js" />
If bundling is turned on, the single output file contains the 'async' and 'defer' name-only attributes. When bundling is turned off, then those name-only attributes are applied to each individual file reference.
This processor only supports files that end in .js and .css
ResourceBundlingService}| Modifier and Type | Field and Description |
|---|---|
protected ResourceBundlingService |
bundlingService |
| Constructor and Description |
|---|
ResourceBundleProcessor() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addElementToModel(String src,
boolean async,
boolean defer,
org.broadleafcommerce.presentation.model.BroadleafTemplateContext context,
org.broadleafcommerce.presentation.model.BroadleafTemplateModel model) |
protected boolean |
getBundleEnabled() |
protected String |
getBundleUrl(String bundleName,
org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
Adds the context path to the bundleUrl.
|
protected Map<String,String> |
getLinkAttributes(String src) |
String |
getName() |
int |
getPrecedence() |
org.broadleafcommerce.presentation.model.BroadleafTemplateModel |
getReplacementModel(String tagName,
Map<String,String> tagAttributes,
org.broadleafcommerce.presentation.model.BroadleafTemplateContext context) |
protected Map<String,String> |
getScriptAttributes(String src,
boolean async,
boolean defer) |
protected ResourceBundlingService bundlingService
protected boolean getBundleEnabled()
public String getName()
public int getPrecedence()
getPrecedence in interface org.broadleafcommerce.presentation.dialect.BroadleafProcessorgetPrecedence in class org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessorpublic org.broadleafcommerce.presentation.model.BroadleafTemplateModel getReplacementModel(String tagName, Map<String,String> tagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
protected String getBundleUrl(String bundleName, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
arguments - bundleName - protected void addElementToModel(String src, boolean async, boolean defer, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context, org.broadleafcommerce.presentation.model.BroadleafTemplateModel model)
protected Map<String,String> getScriptAttributes(String src, boolean async, boolean defer)
Copyright © 2021. All rights reserved.