Web pages typically reference a lot of fairly static content files
such as images and Javascripts, which change infrequently if ever. Web browsers are able to cache such static content, but they conservatively keep going back to the server to check whether their cached copy of the content is still valid. They do this by sending requests with the If-Modified-Since: header. If the resource has been modified since it was last transferred, it is transferred again, otherwise the browser uses the cached copy that it has. This protocol saves having to transfer content that has not changed, but it still involves a round trip to the server. Across a high-latency network, all these round trips to the server result in significant
degradation in user interface responsiveness.
These round trip requests can be reduced or eliminated by setting
an expiration time on content sent by the server. The server does this
by adding the header Expires: or Cache-Control: to the response. Both
tell the browser that it may cache and not re-check the validity of the content for a specific amount of time. When the cached content expires, the browser once again sends an If-Modified-Since: request, receives a new expiration time, and the cycle repeats.
Static content declarations are located in the fragment SERVERHOME/PLATFORM/resources/warutil/fragment/M1DeploymentUtilities.static_content.web.xml.part.
The following example is the configuration provided out of the box
to cache specified static browser content for a period of 7 days. The
browser will cache and not re-check the validity of the content for a
7days.
<filter>
<filter-name>StaticContentCaching</filter-name>
<filter-class>com.matrixone.servlet.StaticContentCaching</filter-class>
<init-param>
<param-name>ematrix.cache-control.ResourceLifetime</param-name>
<param-value>7d</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.css</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.xsl</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StaticContentCaching</filter-name>
<url-pattern>*.jpg</url-pattern>
</filter-mapping>
You can modify, add, and remove filter-mapping entries
in this configuration. Each entry enables the cache control for a specific
file type.
ematrix.cache-control.ResourceLifetime—Sets the amount of time to
cache static browser content in the configuration. For example, the parameter could be:
<init-param>
<param-name>ematrix.cache-control.ResourceLifetime</param-name>
<param-value>7d</param-value>
</init-param>
The default is 7d. Select a number followed by a single
character, s (seconds), m (minutes), h (hours), or d (days). A value
of zero turns off the filter and no cache control is enabled. A value
of 0s means expire immediatly or after zero seconds.