...
Components learn about assets via injection. The @Inject annotation allows Assets to be injected into components as read-only properties. The path to the resource is specified using the Path annotation:
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("context:images/tapestry_banner.gif") private Asset banner; |
Assets are located within domains; these domains are identified by the prefix on the @Path annotation's value
.
...
Assets can also be referenced directly in templates. Two binding prefixes exist for this: "asset:" and "context:". The "asset:" prefix can obtain assets from the classpath (the default) or from the web context (by specifying the "context:" domain explicitly):
Code Block | ||||
---|---|---|---|---|
| ||||
<img src="${asset:context:image/tapestry_banner.gif}" alt="Banner"/>
|
...
Because accessing context assets is so common, the "context:" binding prefix was introduced:
Code Block | ||||
---|---|---|---|---|
| ||||
<img src="${context:image/tapestry_banner.gif}" alt="Banner"/>
|
...
You can use relative paths with domains (if you omit the prefix):
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("../edit.png") private Asset icon; |
Since you must omit the prefix, this only makes sense for components packaged in a library for reuse.
...
Symbols inside the annotation value are expanded. This allows you to define a symbol and reference it as part of the path. For example, you could contribute a symbol named "skin.root" as "context:skins/basic" and then reference an asset from within it:
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("${skin.root}/style.css") private Asset style; |
Note |
---|
The use of the |
...
You should have an explicit application version number for any production application. Client browsers will aggressively cache downloaded assets; they will usually not even send a request to see if the asset has changed once the asset is downloaded the first time. Because of this is is very important that each new deployment of your application has a new version number (tapestry.application-version|Configuration]: this will force existing clients to re-download all files.
...
Since version 5.3, Tapestry provides a service, ResourceMinimizer, which will help to minimize all your static resources : stylesheets, (principally CSS and JavaScript files .)..
By default, this service does nothing. You should include a third-party library, for example the tapestry-yuicompressor project, which makes it possible to minimize CSS and JavaScript files.
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency> <groupId>org.apache.tapestry</groupId> <artifactId>tapestry-yuicompressor</artifactId> <version>5.3.1</version> </dependency> |
By adding this dependency, all your JavaScript and CSS files will be minimized , when you are in PRODUCTION_MODE=true. You can force the minimization of these files, by changing the value of the constant SymbolConstants.MINIFICATION_ENABLED in your module class (usually AppModule.java):
Code Block | ||
---|---|---|
| ||
@Contribute(SymbolProvider.class) @ApplicationDefaults public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration) { configuration.add(SymbolConstants.MINIFICATION_ENABLED, "true"); } |
If you want to add your own minimizer, you can contribute to the ResourceMinimizer service. The service configuration maps the MIME-TYPE of your resource to an implementation of the ResourceMinimizer interface.
Code Block | ||
---|---|---|
| ||
@Contribute(ResourceMinimizer.class)
@Primary
public static void contributeMinimizers(MappedConfiguration<String, ResourceMinimizer> configuration)
{
configuration.addInstance(" text/coffeescript", CoffeeScriptMinimizer.class);
}
|
...
Footnotes Display |
---|