|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.click.extras.filter.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:Control.getHtmlImports() automatically
removes duplicate scripts.<html> <head> $cssImports </head> <body> $table </body> </html> $jsImportsCSS imports should be included in the head section of your page, and the JavaScript imports should be included at the bottom of your page to support progressive rendering in the browser.
<filter> <filter-name>PerformanceFilter</filter-name> <filter-class>net.sf.click.extras.filter.PerformanceFilter</filter-class> <init-param> <param-name>cachable-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> ..This filter will automatically set the configured click.xml charset as the requests character encoding.
| Field Summary | |
protected long |
cacheMaxAge
The configured cache max age in seconds, default value is 1 year. |
protected int |
compressionThreshold
The threshold number to compress, default value is 384 bytes. |
protected ConfigService |
configService
The application configuration service. |
protected boolean |
configured
The fitler has been configured flag. |
protected static int |
DEFAULT_CACHE_MAX_AGE
Default cache max-age in seconds (1 year): 31536000. |
protected List |
excludeDirs
The cachable-path exclude directories. |
protected List |
excludeFiles
The cachable-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 |
includeDirs
The cachable-path include directories. |
protected List |
includeFiles
The cachable-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 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 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 configure cache max-age. |
protected boolean |
useForeverCacheHeader(String path)
Return true if a path is a static versioned Click resource and should be cached forever. |
protected boolean |
useGzipCompression(HttpServletRequest request,
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 configured
protected ConfigService configService
protected FilterConfig filterConfig
protected List includeDirs
protected List includeFiles
protected List excludeDirs
protected List excludeFiles
| Constructor Detail |
public PerformanceFilter()
| Method Detail |
public void init(FilterConfig filterConfig)
init in interface FilterfilterConfig - The filter configuration objectFilter.init(FilterConfig)public void destroy()
destroy in interface FilterFilter.destroy()
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain chain)
throws IOException,
ServletException
doFilter in interface FilterservletRequest - 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 String getResourceVersionIndicator(String path)
path - the resource path
protected String stripResourceVersionIndicator(String path)
path - the resource path
getResourceVersionIndicator(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(String)protected boolean useConfiguredCacheHeader(String path)
path - the request path to test
protected boolean useGzipCompression(HttpServletRequest request,
String path)
request - the request to testpath - the request path to test
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||