I ran Google's Page Speed on our web app to analyze and optimize our web site .
One of the many items under Web Performance Best Practices as listed in Page Speed says "To take advantage of the full benefits of caching consistently across all browsers, we recommend that you configure your web server to explicitly set caching headers and apply them to all cacheable static resources, not just a small subset (such as images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDFs, Flash files, etc.). In general, HTML is not static, and shouldn't be considered cacheable."
How do I configure tomcat to achieve the same ? I know it can be done via Filters by putting some HTTP headers but can we do it without touching code just by configuration ?
Edit : Just for information we use JSF 1.2 although I think this is irrelevant in context of this question.
If you are on Tomcat7, there is a built-in filter for that. http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#Expires_Filter
We use the wonderful URlRewriteFilter to do this. No code change, just configuration to web.xml, that's all. Link and rule below.
http://tuckey.org/urlrewrite/
<rule>
<from>^.*\.(js|css|gif)$</from>
<set type="expires">6 hours</set>
</rule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With