This is a basic question about how to get started with resource loading in RF4.1. Apologies for the wordiness - but I wanted to show my working, as well as the problem I'm having.
QUESTION: What am I doing wrong in the following set-up? Why are my resources not getting packed/minified?
I am completely new to resource loading strategies in Java web apps - so this could be a problem between the keyboard and the chair.
I have recently upgraded from RF 4.0 to RF 4.1. I am trying to take advantage of the new compressing and packing (a.k.a. minification, I assume) features now available in 4.1.
So far, I've focused on packing/minification, but have not been able to get a working configuration.
The main components I'm using are:
- GlassFish 3.1.1
- RichFaces 4.1.0.Final
- YSlow (for feedback - what's packed/compressed; what's unpacked)
For the purposes of this exercise, I have the PROJECT_STAGE set to "Production" in the application's web.xml.
As an aside, Glassfish is configured to compress anything for the following mime types:
The compression threshold, just for this exercise, is set to 128 bytes (usually I use the default value of 2048 bytes). I don't think that is relevant - but I mention it in case it is.
So, for example, using YSlow, I can see that:
- jquery.js is compressed from 238.1KB to 79.3KB
2. THE PROBLEM
I see 29 components that are not getting packed/minified, for example:
3. FIRST ATTEMPT
I look at chapter 5 of the 4.1.X Developer Guide, to see if I can pack/minify the above resources. I skip over section 5.4.2 and jump (maybe misguidedly) to section 5.4.3.
I add the following to my web.xml, as described in the Developer Guide, section "18.104.22.168. Configuring resource loading strategies":
Now I see only 5 components that are not getting minified - but all the ajax functions in my application are no longer responsive (e.g. expanding/collapsing panels no longer happens). Also, I placed a a4j:log component at the foot of the page - that component is not displayed.
I guess the new minified versions of these resources cannot be found in the old, expected locations. I guess I therefore need to tell my application where to look - so, I go back to the content I skipped over earlier!
4. SECOND ATTEMPT
I revisit, with chagrin, the earlier section - 22.214.171.124 and the related sub-sections.
I add this to my web.xml:
I take the "Packed.properties" file from /META-INF/richfaces/staticResourceMapping/ in the following JAR: richfaces-components-ui.jar. I add the contents to my custom-mapping.properties file. I create an ant task to ensure this gets added to the META-INF directory in my project war file:
Now, my web site runs OK again - ajax is responsive again - but I've reverted to YSlow telling me that "there are 30 components that can be minified" - for example:
5. THIRD ATTEMPT
I try adding the following to web.xml:
and, when that does not work (i.e. resources still not minified), also this:
I was not sure whether I should have used ".../javax.faces.resource/..." or ".../faces/javax.faces.resource/...". But neither appears to be what is needed.
Both of these result in the same YSlow feedback - 30 components not being minified.
So, I can get either:
- resources not minified, but site is working
- resources mostly minified, but site is not working
There's a note at the end of section 126.96.36.199 which states:
"Resource loading strategies are just special case of resource mapping, thus once you will provide custom resource mapping configuration or location, bundled default resources won't be referenced correctly.
"For using compressed/packed resources you will need to copy properties from one of files located in richfaces-components-ui.jar:/META-INF/richfaces/staticResourceMapping/."
I was not sure how to interpret this information. I guess the above walk-through shows you how close to (or far from) the correct answer I was.