|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.extras.filter.PerformanceFilter
public class PerformanceFilter
Provides a filter for improving the performance of web applications by setting Expires header on static resources and by compressing the HTTP response.
Please see Yahoo's Exceptional Performance best practices for speeding up your web site. This filter will enable you to apply the rules: Apache Click can also help you with the following rules:Control.getHeadElements()
automatically
removes duplicate scripts.<filter> <filter-name>PerformanceFilter</filter-name> <filter-class>org.apache.click.extras.filter.PerformanceFilter</filter-class> <init-param> <param-name>application-version</param-name> <param-value>1.0</param-value> </init-param> </filter>Application versioning is supported by
resource elements
such as JsImport
and
CssImport
. When the
application version is set, ResourceElements
will add the application version number to their filenames
and PerformanceFilter will apply the long expiry header to these versioned files.
When you increment the application version, the resource path will
change and the static resources will be requested again and cached by the
browser.
PerformanceFilter provides GZIP compression to compress HTML ServletResponse
content. The content will only be compressed if it is bigger than a
configurable threshold. The default threshold is 384 bytes but can be changed
through the init-param "compression-threshold".
Click *.htm pages are automatically compressed by the filter.
It is also possible to disable GZIP compression by setting the
init-param "compression-enabled" to false.
<html> <head> $headElements </head> <body> $table </body> </html> $jsElementsHEAD elements should be included in the head section of your page, and JavaScript elements should be included at the bottom of your page to support progressive rendering in the browser.
<filter> <filter-name>PerformanceFilter</filter-name> <filter-class>org.apache.click.extras.filter.PerformanceFilter</filter-class> <init-param> <param-name>cacheable-paths</param-name> <param-value>/assets/*, *.css</param-value> </init-param> </filter> <filter-mapping> <filter-name>PerformanceFilter</filter-name> <url-pattern>*.css</url-pattern> </filter-mapping> <filter-mapping> <filter-name>PerformanceFilter</filter-name> <url-pattern>*.js</url-pattern> </filter-mapping> <filter-mapping> <filter-name>PerformanceFilter</filter-name> <url-pattern>*.gif</url-pattern> </filter-mapping> <filter-mapping> <filter-name>PerformanceFilter</filter-name> <url-pattern>*.png</url-pattern> </filter-mapping> <filter-mapping> <filter-name>PerformanceFilter</filter-name> <servlet-name>ClickServlet</servlet-name> </filter-mapping> <servlet> <servlet-name>ClickServlet</servlet-name> ..The init-param "cacheable-paths", allows you to specify paths for resources such as JavaScript, CSS and images to be cached by the browser. (Caching here means setting the "Expires" and "Cache-Control" headers). The param-value accepts a comma separated list of directories and files to match against. To differentiate between directory and file values the following convention is used:
Field Summary | |
---|---|
protected String |
applicationVersionIndicator
The application resource version indicator. |
protected long |
cacheMaxAge
The configured cache max age in seconds, default value is 1 year. |
protected boolean |
compressionEnabled
Indicates if compression is enabled or not, default value is true. |
protected int |
compressionThreshold
The threshold number to compress, default value is 384 bytes. |
protected ConfigService |
configService
The application configuration service. |
protected boolean |
configured
The filter has been configured flag. |
protected static int |
DEFAULT_CACHE_MAX_AGE
Default cache max-age in seconds (1 year): 31536000. |
protected List<String> |
excludeDirs
The cacheable-path exclude directories. |
protected List<String> |
excludeFiles
The cacheable-path exclude files. |
protected FilterConfig |
filterConfig
The filter configuration object we are associated with. |
protected static int |
FOREVER_CACHE_MAX_AGE
Forever cache max-age in seconds (5 years). |
protected List<String> |
includeDirs
The cacheable-path include directories. |
protected List<String> |
includeFiles
The cacheable-path include files. |
protected static int |
MIN_COMPRESSION_THRESHOLD
Minimum compress threshold: 384 bytes. |
Constructor Summary | |
---|---|
PerformanceFilter()
|
Method Summary | |
---|---|
void |
destroy()
Take this filter out of service. |
void |
doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain chain)
Perform the filter operation applying any necessary Expire headers and compressing the response content. |
protected String |
getApplicationResourceVersionIndicator(String path)
Return the application version indicator for the specified path. |
protected ConfigService |
getConfigService()
Return the application configuration service. |
FilterConfig |
getFilterConfig()
Return filter config. |
protected String |
getResourceVersionIndicator(String path)
Return the version indicator for the specified path. |
void |
init(FilterConfig filterConfig)
Initialize the filter. |
protected boolean |
isExcludePath(String path)
Return true if a path should be excluded from the performance filter. |
protected void |
loadConfiguration()
Load the filters configuration and set the configured flat to true. |
void |
setFilterConfig(FilterConfig filterConfig)
Set filter configuration. |
protected void |
setHeaderExpiresCache(HttpServletResponse response,
long maxAgeSeconds)
Set the response "Expires" and "Cache-Control" headers with the given maximum cache duration age in seconds. |
protected String |
stripResourceVersionIndicator(String path)
Removes the version indicator from the specified path. |
protected boolean |
useConfiguredCacheHeader(String path)
Return true if the response should be cached using the configured cache max-age. |
protected boolean |
useForeverCacheHeader(String path)
Return true if a path is a static versioned resource and should be cached forever. |
protected boolean |
useGzipCompression(HttpServletRequest request,
HttpServletResponse response,
String path)
Return true if the response should be GZIP compressed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int DEFAULT_CACHE_MAX_AGE
protected static final int FOREVER_CACHE_MAX_AGE
protected static final int MIN_COMPRESSION_THRESHOLD
protected long cacheMaxAge
protected int compressionThreshold
protected boolean compressionEnabled
protected boolean configured
protected ConfigService configService
protected FilterConfig filterConfig
protected List<String> includeDirs
protected List<String> includeFiles
protected List<String> excludeDirs
protected List<String> excludeFiles
protected String applicationVersionIndicator
Constructor Detail |
---|
public PerformanceFilter()
Method Detail |
---|
public void init(FilterConfig filterConfig)
init
in interface Filter
filterConfig
- The filter configuration objectFilter.init(FilterConfig)
public void destroy()
destroy
in interface Filter
Filter.destroy()
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
servletRequest
- the servlet requestservletResponse
- the servlet responsechain
- the filter chain
IOException
- if an I/O error occurs
ServletException
- if a servlet error occursFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
public void setFilterConfig(FilterConfig filterConfig)
filterConfig
- the filter configuration objectpublic FilterConfig getFilterConfig()
protected ConfigService getConfigService()
protected void loadConfiguration()
protected boolean isExcludePath(String path)
path
- the request path to test
protected String getResourceVersionIndicator(String path)
path
- the resource path
protected String getApplicationResourceVersionIndicator(String path)
path
- the resource path
protected String stripResourceVersionIndicator(String path)
path
- the resource path
getResourceVersionIndicator(String)
,
getApplicationResourceVersionIndicator(java.lang.String)
protected void setHeaderExpiresCache(HttpServletResponse response, long maxAgeSeconds)
response
- the response to set the headers inmaxAgeSeconds
- the maximum cache duration in secondsprotected boolean useForeverCacheHeader(String path)
path
- the request path to test
getResourceVersionIndicator(java.lang.String)
,
getApplicationResourceVersionIndicator(java.lang.String)
protected boolean useConfiguredCacheHeader(String path)
path
- the request path to test
protected boolean useGzipCompression(HttpServletRequest request, HttpServletResponse response, String path)
request
- the request to testresponse
- the response to testpath
- the request path to test
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |