This is a Java servlet filter (as per Servlet API 2.3). trimFilter lets you decrease the size of file your server will send to all clients. Filter removes extra spaces and line breaks from outputted documents. Especially useful for WAP/WML developers, where the size for transferred documents is limited. How to use it: a) download trimflt.jar and save it in WEB-INF/lib b) describe this filter in web.xml
<filter> <filter-name>trimFilter</filter-name> <filter-class>com.cj.trim.trimFilter</filter-class> </filter> You can set also an initial parameter removeComments. In this case
filter will remove HTML comments too:
<filter> <filter-name>trimFilter</filter-name> <filter-class>com.cj.trim.trimFilter</filter-class> <init-param> <param-name>removeComments</param-name> <param-value>true</param-value> </init-param> </filter> default value for this parameter is false (do not remove comments). Also you may exclude some of your files from the processing. Parameter
exclude contains regular expresion to match excluded urls. E.g.:
<filter> <filter-name>trimFilter</filter-name> <filter-class>com.cj.trim.trimFilter</filter-class> <init-param> <param-name>exclude</param-name> <param-value>/login.jsp</param-value> </init-param> </filter> By default this parameter is empty (do not exclude files). You can set also an initial parameter keepStrings. In this case
filter will keep data for strings (texts between " " or ' ') as is:
<filter> <filter-name>trimFilter</filter-name> <filter-class>com.cj.trim.trimFilter</filter-class> <init-param> <param-name>keepStrings</param-name> <param-value>true</param-value> </init-param> </filter> default value for this parameter is false. An optional parameter expires describes a caching time (client side cache) for your pages in seconds. c) describe a mapping for this filter in web.xml
<filter-mapping> <filter-name>trimFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> in this case filter will be on for the each .jsp file And now when you invoke any .jsp page: http://your_host/your_page.jsp trimFilter will compress their output.
For downloading: trimflt.jar You can buy a commercial license here.
See also JSOS - the largest collection of servlets and filters. |
Also in Coldtags:
|