Introduction
Java Server Faces 2 comes with resources and resource libraries, a notion which helps in managing dependencies of components.
Each component defines its dependencies on JavaScript / CSS resources and JSF makes sure the links for loading these resources are included in the page when the component is rendered.
When using resource libraries the way component libraries like RichFaces does, a lot of resource links are generated to the page, leading to many requests to obtain these resources for first-time visitors (when resources are not yet cached), which can be a real performance problem.
A second problem is brought upon by RichFaces itself, since some of resources (ECSS, generated images) are generated in runtime, which can be problematic in certain runtime environments (ie. Google App Engine). Without intervention, RichFaces would be unable to work in such environments.
That's why RichFaces can pre-process resources at build time and that's what you can achieve with custom resources too.
Using generated resources
There are two ways of using pre-generated resources:
- using RichFaces Resource Optimization feature
- using maven-richfaces-resources-plugin to generate customized set of resources
- and configuring RichFaces Resource Mapping to grab these resources
Using resources generated in build of RichFaces Components
Simplest option is use pre-generated and tested resources which are bundled in richfaces-components-ui.jar.
These resources are pre-generated in all possible versions (packed, compressed and packed+compressed)
and there are also prepared configurations to load these resources.
More details about configuring RichFaces to grab these resources can be found in RichFaces Resource Optimization documentation in blog on Optimizing Resource Loading.
Generating customized set of resources
But in some cases, it's desired to generate custom set of resources:
- you want to pack jsf.js (JavaScript part of JSF implemention) with rest of component resources
- you are using custom components
By default, RichFaces does not know about specific JSF implementation used in your project, that's why jsf.js resource is not packed in RichFaces Components bundle. To further optimize resource loading, it's possible to pack jsf.js in your target application, to optimize resource loading to maximum level.
Second basic usage of generating customized set of resources is when you are using custom components and you want their resources to be processed.
In this case, refer to the documentation of maven-richfaces-resources-plugin.
Note: currently plugin is not able to search for custom application resources, referenced by <h:outputScript /> and <h:outputStylesheet /> (you can vote for this issue).
Refer to RichFaces Resource Mapping documentation for details how to let RichFaces grab these resources.
Goals of the RichFaces CDK: Resources Maven Plugin
maven-richfaces-resources-plugin intents to
- generate static equivalents of resources,
- package them into single files per resource and
- compress them.
Static equivalents ensures that dynamic resources are generated in build time and thus no runtime restrictions are applied to these resources and it also gives performance improvement over dynamic generation and caching in runtime.
Packaging decrease number of HTTP requests required for fetching mandatory application dependencies.
Compression makes sure the amount of data to be transfered to application client is as low as possible.
More info about maven-richfaces-resources-plugin can be found in plugin documentation.
Comments