Stop browser scripts caching in GWT App

前端 未结 2 1307
刺人心
刺人心 2020-12-13 21:11

I have a GWT app deployed onto our client\'s machines. As an ongoing development alongside, we have to release new improved versions of the application fron time to time. Ev

2条回答
  •  时光取名叫无心
    2020-12-13 21:46

    Possible solution depends on the way you are hosting your application. If you are hosting directly from servlet container, then you can use servlet filter like the one described here:

    http://seewah.blogspot.com/2009/02/gwt-tips-2-nocachejs-getting-cached-in.html

    Here are appropriate filters from tadedon library:

    http://code.google.com/p/tadedon/source/browse/tadedon-servlet/src/main/java/com/xemantic/tadedon/servlet/CacheDisablingFilter.java

    http://code.google.com/p/tadedon/source/browse/tadedon-servlet/src/main/java/com/xemantic/tadedon/servlet/CacheForcingFilter.java

    And here is guice ServletModule which enables them for the whole guice web application:

    http://code.google.com/p/tadedon/source/browse/tadedon-gwt/src/main/java/com/xemantic/tadedon/gwt/http/GwtHttpCachingModule.java

    If you are using some reverse proxy in front of tomcat it would be even simpler. In case of apache (e.g. mod_proxy, mod_jk), and assuming that all the application resources (html, graphics, java scripts, css, etc.) are put on apache, just set these options in apache configuration:

    
      ExpiresDefault "access"
    
    
    
      ExpiresDefault "now plus 1 year"
    
    

    It is described here:

    http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html

    in "Perfect Caching" section. Such deployment scenario assumes that only rpc requests should go through reverse proxy to tomcat. If for some reasons all the application context is proxied to tomcat you can still use apache's LocationMatch directive instead of Files directive.

提交回复
热议问题