GWT 2.4 & Jetty nocache.js files

718 views
Skip to first unread message

brent...@gmail.com

unread,
Jul 18, 2012, 10:50:15 AM7/18/12
to google-we...@googlegroups.com

In this gwt web says to place a *.htaccess config file like this to avoid caching main javascript gwt application.

<Files *.nocache.*>
  ExpiresActive on
  ExpiresDefault "now"
  Header merge Cache-Control "public, max-age=0, must-revalidate"
</Files>

<Files *.cache.*>
  ExpiresActive on
  ExpiresDefault "now plus 1 year"
</Files>

Is there a way to do the same with Jetty ? (whithout needing to use httpd jetty module)

We're using an embedded jetty container version 7.3.1.v20110307.

brent...@gmail.com

unread,
Jul 18, 2012, 11:57:41 AM7/18/12
to google-we...@googlegroups.com
I figured out the answer.  All I had to do was add this to my web.xml file.

<servlet>

<servlet-name>default</servlet-name>

<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>

<init-param>

<param-name>cacheControl</param-name>

<param-value>public, max-age=0, must-revalidate</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>default</servlet-name>

<url-pattern>/myApp/*.nocache.js</url-pattern>

</servlet-mapping>


Thanks!

Joseph Lust

unread,
Jul 18, 2012, 11:59:30 AM7/18/12
to google-we...@googlegroups.com
You just need to add a filter to your web.xml file. This is lifted from a SO article. This example just does the *.cache.* files, but adding another filter with the proper regex would also handle your *.nocache.* files.

<filter>
    <filter-name>Header Filter</filter-name>
    <filter-class>com.liferay.portal.kernel.servlet.PortalClassLoaderFilter</filter-class>
    <init-param>
        <param-name>filter-class</param-name>
        <param-value>com.liferay.portal.servlet.filters.header.HeaderFilter</param-value>
    </init-param>
    <init-param>
        <param-name>url-regex-pattern</param-name>
        <!-- the following matches everything except files ending .nocache.js  -->
        <param-value><![CDATA[^.+(?<!nocache\.js)$]]></param-value>
    </init-param>
    <init-param>
        <param-name>Cache-Control</param-name>
        <param-value>max-age=315360000, public</param-value>
    </init-param>
    <init-param>
        <param-name>Expires</param-name>
        <param-value>315360000</param-value>
    </init-param>
</filter>

Sincerely,
Jospeh

fedex

unread,
Jun 27, 2013, 5:42:48 PM6/27/13
to google-we...@googlegroups.com
hey can I use the same code for my application? what else will change if I have to use for mine? This filter will help us with cache issues right?
Reply all
Reply to author
Forward
0 new messages