Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop browser scripts caching in GWT App

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. Everytime we release a new version we often run into the problem where the client's browser has cached the old scripts scriptsand for a while it behaves strangly as the data it is trying to work with is not quite compatible with it. What is the best way to overcome this problem. Currently I have to tell the users to clear their browser's cache for a new release but it would be nice they don't have to do this.

like image 542
Shahid Avatar asked Aug 04 '10 16:08

Shahid


People also ask

How do I stop my browser from caching?

When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache. You can then close out of Developer Tools.

What is Nocache JS in GWT?

nocache. js file contains JavaScript code that resolves the Deferred Binding configurations (such as browser detection, for instance) and then uses a lookup table generated by the GWT Compiler to locate one of the . cache.

What does browser caching reduce?

Caching minimizes the number of queries that are sent to your server, which takes longer to process than cached results. This is the main reason for caching and how it may improve page performance, load time, and better user experience. While load times are crucial, caching also lowers network costs.


1 Answers

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:

<Files *.nocache.*>
  ExpiresDefault "access"
</Files>

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

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.

like image 69
morisil Avatar answered Sep 22 '22 23:09

morisil