You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2010/06/14 09:53:06 UTC

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.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 & Browser Caching

Posted by Greg Lindholm <gr...@gmail.com>.
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>
    <description>Cache-Control for static resources</description>
    <filter-name>StaticCacheControlFilter</filter-name>
    <filter-class>com.allmanint.common.servlet.SetHeadersFilter</filter-class>
    <init-param>
      <param-name>Cache-Control</param-name>
      <param-value>max-age=3600, must-revalidate</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>StaticCacheControlFilter</filter-name>
    <url-pattern>/images/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>StaticCacheControlFilter</filter-name>
    <url-pattern>/css/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>StaticCacheControlFilter</filter-name>
    <url-pattern>/js/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>StaticCacheControlFilter</filter-name>
    <url-pattern>*.ico</url-pattern>
  </filter-mapping>



On Mon, Jun 14, 2010 at 9:14 AM, James Cook <Ja...@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.varley@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


RE: Struts 2 & Browser Caching

Posted by James Cook <Ja...@wecomm.com>.
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.varley@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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


RE: Struts 2 & Browser Caching

Posted by RogerV <ro...@googlemail.com>.


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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts 2 & Browser Caching

Posted by James Cook <Ja...@wecomm.com>.
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.varley@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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


RE: Struts 2 & Browser Caching

Posted by RogerV <ro...@googlemail.com>.


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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts 2 & Browser Caching

Posted by James Cook <Ja...@wecomm.com>.
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.varley@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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


[Struts 2.1.8.1 and JBoss 6.0.0 M3] cvc-datatype-valid.1.2.1: '2.2.3' is not a valid value for 'decimal'

Posted by Celinio Fernandes <ce...@yahoo.com>.
Hi,
I already had this error in the past (with Struts 2.1.8 and Jboss 6.0.0 M1).
And I know there is a JIRA issue about it :
https://issues.apache.org/jira/browse/WW-3299

And I already asked about this error in the past. I fixed it by extracting the struts-tag.tld file from the library struts2-core-2.1.8.1.jar and modifying the tlib version by shortening it like this :
<tlib-version>2.2.3</tlib-version>
==>
<tlib-version>2.2</tlib-version>

I then reconstructed the library struts2-core-2.1.8.1.jar with the modified struts-tag.tld file.

But i also get tons of errors regarding the <display-name> and <description> tags.
For instance :
 <display-name>"Struts Tags"</display-name>  <description><![CDATA[Execute an action from within a view]]></description> It seems i now also need to remove these 2 tags (hundreds of lines in the TLD file).

Isn't there a quick fix for it ? I always waste a lot of time fixing this versioning problem when i set up a new environment with Jboss and Struts 2.

Thanks for helping.

Here is a part of the stacktrace when i try to deploy the webapp: 

Caused by: org.jboss.xb.binding.JBossXBException: Failed to parse source: cvc-datatype-valid.1.2.1: '2.2.3' is not a valid value for 'decimal'. @ vfs:///K:/jboss-6.0.0.20100429-M3/server/default/deploy/Chapitre1.war/WEB-INF/lib/struts2-core-2.1.8.1.jar/META-INF/struts-tags.tld[9,37]
    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:195) [jbossxb.jar:2.0.2.Beta7]
    at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168) [jbossxb.jar:2.0.2.Beta7]
    at org.jboss.xb.util.JBossXBHelper.parse(JBossXBHelper.java:229) [jbossxb.jar:2.0.2.Beta7]
    at org.jboss.xb.util.JBossXBHelper.parse(JBossXBHelper.java:206) [jbossxb.jar:2.0.2.Beta7]
    at org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer.parse(SchemaResolverDeployer.java:137) [:2.2.0.Alpha4]
    at org.jboss.deployment.TldParsingDeployer.parse(TldParsingDeployer.java:64) [:6.0.0.20100429-M3]
    at org.jboss.deployment.TldParsingDeployer.parse(TldParsingDeployer.java:38) [:6.0.0.20100429-M3]
    at org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer.parse(SchemaResolverDeployer.java:121) [:2.2.0.Alpha4]
    at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parseAndInit(AbstractVFSParsingDeployer.java:315) [:2.2.0.Alpha4]
    at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parse(AbstractVFSParsingDeployer.java:280) [:2.2.0.Alpha4]
    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.createMetaData(AbstractParsingDeployerWithOutput.java:355) [:2.2.0.Alpha4]
    ... 36 more
Caused by: org.xml.sax.SAXException: cvc-datatype-valid.1.2.1: '2.2.3' is not a valid value for 'decimal'. @ vfs:///K:/jboss-6.0.0.20100429-M3/server/default/deploy/Chapitre1.war/WEB-INF/lib/struts2-core-2.1.8.1.jar/META-INF/struts-tags.tld[9,37]