JavaScript trim Filter ver. 1.2


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

How to use it:

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

b) describe this filter in web.xml
 


<filter>
  <filter-name>jstrimFilter</filter-name>
  <filter-class>com.cj.trim.jstrimFilter</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>jstrimFilter</filter-name>
  <filter-class>com.cj.trim.jstrimFilter</filter-class>
  <init-param>
    <param-name>exclude</param-name>
    <param-value>/ajax.js,/form.js</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>jstrimFilter</filter-name>
  <url-pattern>*.js</url-pattern>
</filter-mapping>

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

And now when you include any .js file:
 


<script language="JavaScript" src="your_file.js"></script>

jstrimFilter will compress it.
 

    For downloading:   jstrimflt.jar
 

 ©  Coldbeans     Comments?

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

     

Also in JSOS: