Re: Struts 2 Browser Caching

2010-06-17 Thread Greg Lindholm
We use Tomcat and have written a simple filter to set the cache
control headers on static content. (see below)

We handle the issue with changing JS and CSS files by versioning them
on releases. So when we update a app to version 2 we rename the JS and
CSS files to add a version number so the new pages wont get the old JS
from a cache.

Here is the filter to set headers:
public class SetHeadersFilter implements Filter
{
private FilterConfig _filterConfig;

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain filterChain)
throws IOException, ServletException
{
HttpServletResponse response = (HttpServletResponse) res;

for (Enumeration? e = _filterConfig.getInitParameterNames();
e.hasMoreElements();)
{
String header = (String) e.nextElement();
response.setHeader(header, _filterConfig.getInitParameter(header));
}

filterChain.doFilter(req, res);
}

public void init(FilterConfig filterConfig)
{
this._filterConfig = filterConfig;
}

public void destroy()
{
this._filterConfig = null;
}

}

Here is how we use the filter in web.xml:
  filter
descriptionCache-Control for static resources/description
filter-nameStaticCacheControlFilter/filter-name
filter-classcom.allmanint.common.servlet.SetHeadersFilter/filter-class
init-param
  param-nameCache-Control/param-name
  param-valuemax-age=3600, must-revalidate/param-value
/init-param
  /filter
  filter-mapping
filter-nameStaticCacheControlFilter/filter-name
url-pattern/images/*/url-pattern
  /filter-mapping
  filter-mapping
filter-nameStaticCacheControlFilter/filter-name
url-pattern/css/*/url-pattern
  /filter-mapping
  filter-mapping
filter-nameStaticCacheControlFilter/filter-name
url-pattern/js/*/url-pattern
  /filter-mapping
  filter-mapping
filter-nameStaticCacheControlFilter/filter-name
url-pattern*.ico/url-pattern
  /filter-mapping



On Mon, Jun 14, 2010 at 9:14 AM, James Cook james.c...@wecomm.com wrote:
 Unfortunately they don't say how they managed it, it is mostly people
 complaining that when they change their JS file, without modification to
 the url that accesses the resource the user would have to ctrl+f5 it...

 Sorry :(

 -Original Message-
 From: RogerV [mailto:roger.var...@googlemail.com]
 Sent: 14 June 2010 12:57
 To: user@struts.apache.org
 Subject: RE: Struts 2  Browser Caching




 James Cook-13 wrote:

 Nope, no misunderstanding. All I was saying was that people seem to
 experience the opposite to what you are experiencing. Like you said,
 they have what you want...


 I don't suppose that you happen to have one of your google searches to
 hand
 do you? I'm obviously using the wrong keywords :(

 Regards

 --
 View this message in context:
 http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28878618.htm
 l
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 Browser Caching

2010-06-14 Thread James Cook
I two would like to hear about solutions to this, after a quick Google,
I found most people have it the other way with their JS files being
cached and not reflecting there changes.

How are you constructing your url's for the resources Roger? Do they end
up with a dynamic element in them, that changes every time? Hmm I
wonder, does the jsessionid end up in the url? - would this even cause
the browser to the think it is a fresh url and take a new copy of the
resource?

Laters

James

-Original Message-
From: RogerV [mailto:roger.var...@googlemail.com] 
Sent: 14 June 2010 08:53
To: user@struts.apache.org
Subject: Struts 2  Browser Caching


Hi

While building the functionality of my web-app served up by Apache
Tomcat, I
use 

meta http-equiv=expires content=0   
meta http-equiv=cache-control content=no-cache   
meta http-equiv=pragma content=no-cache 

in all my pages to ensure that requests to the pages with dynamic
content
(most of them) actually reload from the server rather than from the
browser
cache or any intermediate proxy server caches. Now I'm trying to add the
eye-candy and find that as well as going back to the server for data
(good), my browser (Firefox) is reloading all the images, css, js etc
from
the server every time as well(bad) and slowing things down (very bad).

I'd be grateful for any hint/suggestions as to how to force the dynamic
part
of the page to go back to the server but allow the browser to cache the
constant data (images, css etc)? Would running Tomcat behind a
web-server to
load the static data help, or am I pretty much stuffed using the meta
tags?

Regards


-- 
View this message in context:
http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28876782.htm
l
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 Browser Caching

2010-06-14 Thread RogerV



James Cook-13 wrote:
 
 I two would like to hear about solutions to this, after a quick Google,
 I found most people have it the other way with their JS files being
 cached and not reflecting there changes.
 

I think that either I haven't explained clearly or we're misunderstanding
each other - because this is what I want to do. I want all my .js, .css and
images to be cached by the browser, nearby proxy .. whatever but that the
page content - i.e. the result of my action calls are returned to the server
each time for re-loading.

Regards
-- 
View this message in context: 
http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28878060.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 Browser Caching

2010-06-14 Thread James Cook
Nope, no misunderstanding. All I was saying was that people seem to
experience the opposite to what you are experiencing. Like you said,
they have what you want...

-Original Message-
From: RogerV [mailto:roger.var...@googlemail.com] 
Sent: 14 June 2010 11:52
To: user@struts.apache.org
Subject: RE: Struts 2  Browser Caching




James Cook-13 wrote:
 
 I two would like to hear about solutions to this, after a quick
Google,
 I found most people have it the other way with their JS files being
 cached and not reflecting there changes.
 

I think that either I haven't explained clearly or we're
misunderstanding
each other - because this is what I want to do. I want all my .js, .css
and
images to be cached by the browser, nearby proxy .. whatever but that
the
page content - i.e. the result of my action calls are returned to the
server
each time for re-loading.

Regards
-- 
View this message in context:
http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28878060.htm
l
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 Browser Caching

2010-06-14 Thread RogerV



James Cook-13 wrote:
 
 Nope, no misunderstanding. All I was saying was that people seem to
 experience the opposite to what you are experiencing. Like you said,
 they have what you want...
 

I don't suppose that you happen to have one of your google searches to hand
do you? I'm obviously using the wrong keywords :(

Regards

-- 
View this message in context: 
http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28878618.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 Browser Caching

2010-06-14 Thread James Cook
Unfortunately they don't say how they managed it, it is mostly people
complaining that when they change their JS file, without modification to
the url that accesses the resource the user would have to ctrl+f5 it...

Sorry :(

-Original Message-
From: RogerV [mailto:roger.var...@googlemail.com] 
Sent: 14 June 2010 12:57
To: user@struts.apache.org
Subject: RE: Struts 2  Browser Caching




James Cook-13 wrote:
 
 Nope, no misunderstanding. All I was saying was that people seem to
 experience the opposite to what you are experiencing. Like you said,
 they have what you want...
 

I don't suppose that you happen to have one of your google searches to
hand
do you? I'm obviously using the wrong keywords :(

Regards

-- 
View this message in context:
http://old.nabble.com/Struts-2---Browser-Caching-tp28876782p28878618.htm
l
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org