JSF Performance Improvements
1. View State – this will keep on increasing depends upon our page size. The performance might get degraded if the size of this view state increases. Use the following configuration to save the view state in the server side itself.
< context-param >
< param-name > javax.faces.STATE_SAVING_METHOD < / param-name >
< param-value >server < / param-value >
< / context-param >
2. Ajax – As we all know the async request is being made using java scripts. If we have more ajax components in the page, then the following config can be used to compress the script. This is applicable only if we use Rich faces
< context-param >
< param-name > org.ajax4jsf.COMPRESS_SCRIPT < / param-name >
< param-value > true < / param-value >
< / context-param >
This config will enforce the container to compress all the richfaces resources including images, stylesheets, javascript to be compressed before sending to client. It will make significant reduced load time
3. Ajax Parser – By default all the JSF responses are ‘tidied’, we can make only the JSF AJAX response to ‘tidied’. This is applicable only if we use Rich faces
< filter >
< filter-name > richfaces < / filter-name >
< display-name > RichFaces Filter < / display-name >
< filter-class > org.ajax4jsf.Filter < / filter-class >
< init-param >
< param-name > forceparser < / param-name >
< param-value > false < / param-value >
< / init-param >
< / filter >
This can be minimized by setting the forceparser setting to false. In that case only AJAX responses will be ‘tidied’. In the other case all JSF responses are ‘tidied’. That is because the filter is mapped on the Faces servlet: This can be used for partial page rendering.
4. Load strategy - Following configuration will make sure that all style related files should be loaded at client side at once on first request when richfaces application is accessed. This is applicable only if we use Rich faces
< context-param >
< param-name > org.richfaces.LoadStyleStrategy < / param-name >
< param-value > all < / param-value >
< / context-param >
5. Parsers in RichFaces - Richfaces has a few parsers onboard. The default one is based on Tidy, but it is quite slow. The Neko parser is faster and can be used by setting the following context-param’s. This is applicable only if we use Rich faces
< context-param >
< param-name > org.ajax4jsf.xmlparser.ORDER < / param-name >
< param-value > NEKO < / param-value >
< / context-param >
< context-param >
< param-name > org.ajax4jsf.xmlparser.NEKO < / param-name >
< param-value > .*\..* < / param-value >
< / context-param >
6. AJAX tricks :
1. ajaxSingle = true - This attribute should be true for any ajax component whose only value is required at server time so that whole ajax request map should not be posted to server.
2. limitToList = ture – This attribute should be true for any ajax component who will reRender only the components specified in its reRender attribute list. All other components not specified in the reRender list will no longer reRender upon request completion
3. immediate = true – This property will submit the value and skips validation phase and set the value immediately into backing bean.
Best Practices in JSF: