Thanks @Ilya for clarifying on that. Is there any workaround with which we can minimize the JS/CSS generated by richfaces, until the said JIRA tasks are completed?
Also, the readme in Richfaces 4 final bundle recommends use of caching such as ehcache. Can someone help me out on how we can configure ehcache for JSF?
I've made the workaround, so I share it here. It improves page load time dramatically.
All you need is to download this two classes:
you will also need the Apache HTTP Client (http://hc.apache.org/downloads.cgi).
It's also necessary to put following lines to web.xml:
The code is draft-quality (but works fine), so you should review it before usage. Especially you should verify variable named 'self' in ScriptCollectorFilter.java, which contains the address where server is able to connect with self.
It works as follows:
1. The filter is reading the page header.
2. The <script> and <link> tags are removed
3. The single <script> and the single <link> tags are attached at the end of the header content (which points to Collector servlet).
3. If removed scripts and css-files are not cached yet, filter is downloading them and pushing them into Collector caches.
Thanks a TON @Maciej! Like a million tons for your efforts and for your sharing spirit! We were trying on every aspect possible and richfaces's internal css and js were something, we were not able to optimize manually. I'll try your code as soon as possible and get back!
I had upload new version of classes with few bugfixes, so if you will make any test, please download the newst files.
That looks great especially considering that there is still no adjusted plans for having it out of the box. B.t.w. if you will add that to jira as workaround that would help a lot.
Today I added support for gzip content-encoding for output files. This reduces output size 3-4 times, and because compressed content is cached by Collector class, this also reduces CPU usage (time elapsed till first byte of response comes is shorter 1.5 - 2 times) .
@Ilya - I noticed, that you've alredy add link to this thread to jira.
EDIT: Newer version uploaded with one bug fixed (when jsession is send by URL it's necessary to remove it from scripts adresses)
I've been trying you code, but in my case it seems that the filter and servlet is never executed. I tried with simple println statements in the doGet and doPost of servlet and also in the doFilter method of filter. I've made the self related changes and have also added correct entries in the web.xml. What could be the issue here?
@Nikil - Im guessing that "url-pattern" is not set properly to your url mappings. In the configuration that I had sent only "/" and "*.html" are affected by the filter. If you are using another mapping (ex. *.jsf) some changes should be done in filter-mapping section and also in 11th line of doFilter function if(uri.endsWith(".html") || uri.length() < 2) should be changed to match your urls mapping.
Could you send me your web.xml? My address is: maciej.kraus(at)entestat.com. If I found something that may help I'll send it here.
@Maciej: I could solve it, thanks! Yes I had to adjust the URL pattern, and as I'm on https i had to make some changes to the connection part in ScriptCollectorFilter. Also, as I was referring to the httpclient-4.1.1.jar, had to make some changes to the DateUtils code. Since the DateUtils are in the org.apache.http.impl.cookie.DateUtils package now and the DateUtils.parseDate method takes String as params rather than a List<String>. And the code works just fine
When the user tries to access the page for the first time, it takes a little longer to load the page. But for the subsequent requests, it speeds up a lot.
@Maciej: Thank you very much for your contribution of a much needed feature in RF4.
I am running into a problem with compression of richfaces resources and you might able to give me a hint.
First of all, the servlet and the filter works marvelously on all resources except Richfaces.
Reason: Richfaces resources source looks like this: http://localhost:8080/myproject/rfRes/skinning.ecss.jsf?db=eAHL6rC8BQAEkAIG
The Server returns an empty file when the filter is turned on and when the filter is commented out, the server correctly returns the respective file.
I found a workaround for rfRes by replacing it with javax.faces.resource but the problem re-emerges when certain parts of page is loaded later from server through AJAX.
Any clue, why when Filter is turned on, the path with rfRes is not reachable or returns empty?
Attached is my web.xml
web.xml 4.6 K
i am using 22.214.171.12411101-M4 bom, in my project, but this feature is still not supported. I have this in my web.xml:
but the stylesheets are still being loaded on demand;
Did you find any work around for inlcuding the richfaces files? plz let me know if you have any update on this.
Thanks & Regards