Getting Started with JavaScript Optimizer

Follow this steps to install JavaScript Optimizer in your application:

Installation

  • Download JavaScript Optimizer - JSO from sourceforge following the Download section.
    The required archive is the last version of js-optimizer-core-X.X.jar.
    The jar's dependencies can be gathered either by the pom file contained in the jar or simply download the blank application in the section download and copy the content of the lib folder.
  • Place the core jar and the dependencies of JavaScript Optimizer in your webapp lib directory.
  • Your project tree structure should now be :
    +ROOT
    --+WEB-INF
    ----+lib
    ------js-optimizer-core-XXX.jar
    ------%dependencies%.jar

Configuration

Now that JavaScript Optimizer is installed, follow this steps to use it in your application :
  • Add these lines to your web.xml :
    <filter> <filter-name>BrowserCacheFilter</filter-name> <filter-class>com.ideo.jso.filter.BrowserCacheFilter</filter-class> </filter>
    <filter-mapping> <filter-name>BrowserCacheFilter</filter-name> <url-pattern>*.js</url-pattern> </filter-mapping> <filter-mapping> <filter-name>BrowserCacheFilter</filter-name> <url-pattern>*.css</url-pattern> </filter-mapping> <filter-mapping> <filter-name>BrowserCacheFilter</filter-name> <url-pattern>*.jpg</url-pattern> </filter-mapping> <filter-mapping> <filter-name>BrowserCacheFilter</filter-name> <url-pattern>*.gif</url-pattern> </filter-mapping> <filter-mapping> <filter-name>BrowserCacheFilter</filter-name> <url-pattern>*.png</url-pattern> </filter-mapping>
    <servlet> <servlet-name>jso</servlet-name> <servlet-class>com.ideo.jso.servlet.JsoServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jso</servlet-name> <url-pattern>/jso/*</url-pattern> </servlet-mapping>
  • Create a jso.xml configuration file defining the groups of resources to import. (see the XML descriptor section to have more information about this file).
  • Add a <jso:include> tag in the head of your JSP to include the needed groups defined in the previous xml file.

That's it!

Your resources have been imported and cached in your web client !