How to improve performance for serving static files with TOMCAT Follow
If you have ServiceManager version 2.56.0 and up you can ignore this article. In SM new versions there is a built-in support for client caching
The performance of applications can be significantly improved by using the browser capability for client side caching of static resources (e.g. js files, css and more). Reusing previously fetched static resources will make the application to become more responsive.
To activate this capability in the browser, the web server needs to return the HTTP caching headers (e.g. "Expires" and "Cache-Control: max-age" headers). For more information on HTTP caching read this.
With TOMCAT as your web server you can do the following to enable HTTP caching in your browser.
- Stop your tomcat server
- In <tomcat install dir>/conf/ web.xml add the following section:
<filter>
* You can download an example of a full web.xml file with this filter here
<filter-name>ExpiresFilter</filter-name>
<filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
<init-param>
<param-name>ExpiresByType image</param-name>
<param-value>access plus 1 day</param-value>
</init-param>
<init-param>
<param-name>ExpiresByType text/css</param-name>
<param-value>access plus 1 day</param-value>
</init-param>
<init-param>
<param-name>ExpiresByType application/javascript</param-name>
<param-value>access plus 1 day</param-value>
</init-param>
<init-param>
<param-name>ExpiresByType font</param-name>
<param-value>access plus 1 day</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExpiresFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping> - Start Tomcat
With the above configuration the browser will automatically cache JavaScript files, fonts, images and CSS files for a day. You may specify a cache for more than one day by changing the corresponding "<param-value>" nodes.
With Visualizer applications do not try to cache html files as it won't work well.
For more information on Tomcat "ExpiresFilter" read this.
Note
Cache will automatically refresh whenever you will change the content of your application in the Visualizer . This is done automatically as the Visualizer loads all the above resources with additional version parameter (e.g. ../res/dist/auraplayer.js?v=2020.12.20_1645_30). The version value changes on each application "save" thus the cache entry for the old version invalidates and the browser will load it again.
Comments
0 comments
Please sign in to leave a comment.