My favorites | Sign in
Project Logo
                
Code license: Apache License 2.0
Labels: Cache, Filter, Java, J2EE, Browser, HTTP
Show all Featured downloads:
cachefilter-1.0.2.jar
Blogs:
Feeds:
People details
Project owners:
  samaxes

J2EE Cache Filter is a Servlet Filter that allows you to set HTTP headers in order to enable browser caching.

Introduction

From Best Practices for Speeding Up Your Web Site:

Add an Expires or a Cache-Control Header
Web page designs are getting richer and richer, which means more scripts, stylesheets, images, and Flash in the page. A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on all components including scripts, stylesheets, and Flash components.

Configuration

Add the Maven dependency to your pom.xml file:

<dependency>
    <groupId>com.samaxes.cachefilter</groupId>
    <artifactId>cachefilter</artifactId>
    <version>1.0.2</version>
</dependency>

Add the filter configuration to your web.xml file:

<filter>
    <filter-name>imagesCache</filter-name>
    <filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>public</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>2592000</param-value>
    </init-param>
</filter>

<filter>
    <filter-name>cssCache</filter-name>
    <filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>public</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>604800</param-value>
    </init-param>
</filter>

<filter>
    <filter-name>javascriptCache</filter-name>
    <filter-class>com.samaxes.cachefilter.presentation.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>private</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>172801</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>imagesCache</filter-name>
    <url-pattern>/images/*</url-pattern>
</filter-mapping>

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

<filter-mapping>
    <filter-name>javascriptCache</filter-name>
    <url-pattern>*.js</url-pattern>
</filter-mapping>

Repository

Be up to date, add the following to your pom.xml for the most recent version:

<project>
    ...
    <repositories>
        ...
        <repository>
            <id>googlecode-releases</id>
            <name>Google Code Maven repository of releases</name>
            <url>http://maven-samaxes-repo.googlecode.com/svn/releases</url>
        </repository>
        ...
    </repositories>
    ...
</project>

Note: If you still use the version 1.0.1 of J2EE Cache Filter, you will need to copy the following library files into your classpath:









Hosted by Google Code