Maximising Browser Caching
Reduce Network Traffic by Enabling Cache Control headers
Setting the cache control headers for static resources (css, images, javascript) 1) reduces traffic between the server and browser and 2) reduces the requests processed by Tomcat.
It does this by sending information to the browser that allowing it to maximize browser caching.
How to Turn on 'Browser Caching'
- Put MifosResponseHeaderFilter jar into the 'tomcat' lib directory. This is the servlet filter that reads the extra response headers that are set (in web.xml - see later).
- Go to your Tomcat installation directory
- Then go to the sub-directory called conf
- Edit web.xml
- There should be a 'Built In Filter Definitions' section - add the following to the end of that section:
<filter> <display-name>MifosResponseHeaderFilter</display-name> <filter-name>MifosResponseHeaderFilter</filter-name> <filter-class>org.mifos.servlet.filters.MifosResponseHeaderFilter</filter-class> <init-param> <param-name>Cache-Control</param-name> <param-value>max-age=172800, public</param-value> </init-param> </filter> <filter-mapping> <filter-name>MifosResponseHeaderFilter</filter-name> <url-pattern>*.jpg</url-pattern> <url-pattern>*.gif</url-pattern> <url-pattern>*.js</url-pattern> <url-pattern>*.css</url-pattern> </filter-mapping>
- Save web.xml
- Maximising 'Browser Caching' will be turned on next time Tomcat is started.
This will tell the browser that there is no need to request this static resource for 2 days (max-age=172800 - the value is in seconds).
Note:
From ShaminD release, Mifos comes with these cache-control headers already set up in the applications' web.xml
If this 'patch' is applied to the Tomcat/conf/web.xml then it needs to be removed before upgrading to ShaminD (release number and date not currently available).