public class ResourceBundleProcessor
extends org.thymeleaf.processor.element.AbstractElementProcessor
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 boolean |
getBundleEnabled() |
protected String |
getBundleUrl(org.thymeleaf.Arguments arguments,
String bundleName)
Adds the context path to the bundleUrl.
|
protected org.thymeleaf.dom.Element |
getElement(String src,
boolean async,
boolean defer) |
protected org.thymeleaf.dom.Element |
getLinkElement(String src) |
int |
getPrecedence() |
protected org.thymeleaf.dom.Element |
getScriptElement(String src,
boolean async,
boolean defer) |
protected org.thymeleaf.processor.ProcessorResult |
processElement(org.thymeleaf.Arguments arguments,
org.thymeleaf.dom.Element element) |
doProcess, getMatcherprotected ResourceBundlingService bundlingService
protected boolean getBundleEnabled()
public int getPrecedence()
getPrecedence in class org.thymeleaf.processor.AbstractProcessorprotected org.thymeleaf.processor.ProcessorResult processElement(org.thymeleaf.Arguments arguments,
org.thymeleaf.dom.Element element)
processElement in class org.thymeleaf.processor.element.AbstractElementProcessorprotected String getBundleUrl(org.thymeleaf.Arguments arguments, String bundleName)
arguments - bundleName - protected org.thymeleaf.dom.Element getScriptElement(String src, boolean async, boolean defer)
protected org.thymeleaf.dom.Element getLinkElement(String src)
protected org.thymeleaf.dom.Element getElement(String src, boolean async, boolean defer)
Copyright © 2018. All rights reserved.