AssetsPage edited by DEMEY EmmanuelChanges (1)
Full ContentAssetsIn Tapestry, Assets are any kind of static content that may be downloaded to a client web browser, such as images, style sheets and _javascript_ files. Assets are most commonly stored in the web application's context folder ... stored inside the web application WAR file in the usual JEE fashion. In addition, Tapestry treats files stored on the classpath, with your Java class files, as assets visible to the web browser. Assets are exposed to your code as instances of the Asset interface. Injecting AssetsComponents 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: @Inject @Path("context:images/tapestry_banner.gif") private Asset banner;
Performance NotesAssets are expected to be entirely static (not changing while the application is deployed). When Tapestry generates a URL for an asset, either on the classpath or from the context, the URL includes a version number. Further, the asset will get a far future expires header, which will encourage the client browser to cache the asset. In addition, Tapestry will GZIP compress the content of all assets (if the asset is compressible, and the client supports it). 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. Asset SecurityBecause Tapestry directly exposes files on the classpath to the clients, some thought has gone into ensuring that malicious clients are not able to download assets that should not be visible to them. First off all, there's a package limitation: classpath assets are only visible if there's a LibraryMapping for them, and the library mapping substitutes for the initial folders on the classpath. Since the most secure assets, things like hibernate.cfg.xml are located in the unnamed package, they are always off limits. But what about other files on the classpath? Imagine this scenario:
Fortunately, this can't happen. Files with extension ".class" are secured; they must be accompanied in the URL with a query parameter that is the MD5 hash of the file's contents. If the query parameter is absent, or doesn't match the actual file's content, the request is rejected. When your code exposes an Asset, the URL will automatically include the query parameter if the file type is secured. The malicious user is locked out of access to the files 2 . By default, Tapestry secures file extensions ".class', ".tml" and ".properties". The list can be extended by contributing to the ResourceDigestGenerator service contribution. How can we minimize an Asset ?Since version 5.3, Tapestry provides a service, ResourceMinimizer, which will help to minimize all your static resources : stylesheets, _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. pom.xml <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 AppModule.java @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. AppModule.java @Contribute(ResourceMinimizer.class) @Primary public static void contributeMinimizers(MappedConfiguration<String, ResourceMinimizer> configuration) { configuration.addInstance(" text/coffeescript", CoffeeScriptMinimizer.class); }
Change Notification Preferences
View Online
|
View Changes
|
- [CONF] Apache Tapestry > Assets confluence
- [CONF] Apache Tapestry > Assets confluence
- [CONF] Apache Tapestry > Assets confluence
- [CONF] Apache Tapestry > Assets confluence
- [CONF] Apache Tapestry > Assets confluence
