Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT Caching Concept

Can someone explain to me in simple term the concept of caching in GWT. I have read this in many places but may be due to my limited knowledge, i'm not being able to understand it.

Such as nocache.js, cache.js

or other things such as making the client cache files forever or how to make files cached by the client and then if file get changed on the server only then the client download these files again

like image 439
Noor Avatar asked Feb 28 '11 06:02

Noor


2 Answers

Generally, there are 3 type of files -

  1. Cache Forever
  2. Cache for some time
  3. Never Cache

Some files can never be cached, and will always fall in the "never cache" bucket. But the biggest performance wins comes from systematically converting files in the second bucket to files that can be cached forever. GWT makes it easy to do this in various ways.

The <md5>.cache.js files are safe to cache forever. If they ever change, GWT will rename the file, and so the browser will be forced to download it again.

The .nocache.js file should never be cached. This file is modified even if you change a single line of code and recompile. The nocache.js contains the links of the <md5>.cache.js, and therefore it is important that the browser always has the latest version of this file.

The third bucket contains images, css and any other static resources that are part of your application. CSS files are always changing, so you cannot tell the browser 'cache forever'. But if you use ClientBundle / CssResource, GWT will manage the file for you. Every time you change the CSS, GWT will rename the file, and therefore the browser will be forced to download it again. This lets you set strong cache headers to get the best performance.

In summary -

  1. For anything that matches .cache., set a far-in-the-future expires header, effectively telling the browser to cache it forever.
  2. For anything that matches .nocache., set cache headers that force the browser to re-validate the resource with the server.
  3. For everything else, you should set a short expires header depending on how often you change resources.
  4. Try to use ClientBundle / CssResource; this automatically renames your resources to *.cache bucket
like image 117
Sripathi Krishnan Avatar answered Sep 19 '22 12:09

Sripathi Krishnan


This blog post has a good overview of the GWT bootstrapping process (and many other parts of the GWT system, incidentally), which has a lot to do with what gets cached and why.

Basically, the generated nocache.js file is a relatively small bit of JS whose sole purpose is to decide which generated permutation should be downloded.

Each individual permutation consists of the implementation of your app specific to the browser, language, etc., of the user. This is a lot more code than the simple bootstrapping code, and thus needs to be cached for your app to respond quickly. These are the cache.html files that get generated by the GWT compiler.

When you recompile and deploy your app, your users will download the nocache.js file as normal, but this will tell their browsers to download a new cache.html file with the app's new features. This will now be cached as well for the next time they load your app.

like image 42
Jason Hall Avatar answered Sep 20 '22 12:09

Jason Hall