Struts 2 Tip #1 - Always set devMode to false in production
In the Struts 2.0.6 release, we made the mistake of setting devMode to true in some of the example applications. As a result, some developers copied the setting, and then wondered why their Struts 2 application seemed sluggish!
As of Struts 2.0.7 (hopefully coming soon), we've added a Performance Tuning page to the documentation. Here's the highlights:
- Turn off logging and devMode
- Do not use interceptors you do not need
- Use the correct HTTP headers (Cache-Control & Expires)
- Copy the static content from the Struts 2 JAR when using the Ajax theme (Dojo) or the Calendar tag
- Create a
freemarker.propertiesfile in yourWEB-INF/classesdirectory- Copy the
/templatedirectory from the Struts 2 JAR into your web application's root- When overriding a theme, copy all necessary templates to the
themedirectory- Do not create sessions unless you need them
- When using FreemarkerResult, try to use the Freemarker equivalents rather than the JSP tags
For the nitty-gritty, visit the latest copy of the page.
Kudos to Tom Schneider and Philip Luppens for starting the tuning page. If you have any tuning tips of your own, feel free to post comments directly to the page. (Gotta love Confluence!)
HTH, Ted.
Ted Husted is a software engineer and team mentor. His specialty is building agile web applications with open source products like Yahoo! User Interface Library, Struts, Spring, iBATIS, and MySQL, for either Java or Microsoft .NET, and helping others do the same.
Copyright Ted Husted 2007. All rights reserved.