CSS trim Filter ver. 1.2


This is a Java servlet filter (as per Servlet API 2.3). csstrimFilter lets you decrease the size of JavaScript file your server will send to all clients. Filter removes extra spaces and line breaks from CSS code. For modern web applications the size for CSS files is huge, so you can save a lot of traffic with this filter.

How to use it:

a) download csstrimflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml
 


<filter>
  <filter-name>csstrimFilter</filter-name>
  <filter-class>com.cj.trim.csstrimFilter</filter-class>
</filter>

Also you may exclude some of your files from the processing. Parameter exclude contains a commas separated list of files excluded from the processing. E.g.:
 


<filter>
  <filter-name>csstrimFilter</filter-name>
  <filter-class>com.cj.trim.csstrimFilter</filter-class>
  <init-param>
    <param-name>exclude</param-name>
    <param-value>/main.css</param-value>
  </init-param>
</filter>

By default this parameter is empty (do not exclude files).

c) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>csstrimFilter</filter-name>
  <url-pattern>*.css</url-pattern>
</filter-mapping>

in this case filter will be on for the each .css file

And now when you include any .css file:
 


<link rel='stylesheet' type='text/css' href='style.css' />

csstrimFilter will compress it.
 

    For downloading:   csstrimflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

     

Also in JSOS: