i18n Message Generator & Caching of Resources

» Back to forum topics
  2 posts   Feedicon  
Replies: 1 - Last Post: September 12, 2012 11:59
by: deezer
showing 1 - 2 of 2
Posted: September 11, 2012 12:15 by deezer
We're running into an issue with the i18n message generator that generates JavaScript "resource bundles" from Java resource bundles and serves up the proper JavaScript bundle based on the locale of the user.

The i18n message generator itself is working. However, since the bundle filename is not unique per locale, it is causing a certain language to stay in the browser cache (preventing a user from switching locales unless they clear their cache) . Additionally, it is also causing our load balancer to cache a single locale and serve that for all users for the same reason (the filename remains the same and it caches based on filename).

A sample JAWR config that causes this problem may look like this:

That config creates a bundle, /jsbundles/mobile.js that we load from our application using the JAWR HTML loader:
<script src="/jsbundles/jawr_loader.js" ></script>

What is a good solution to prevent the caching of these bundles? It seems like the only solution is to use a unique filename. No other solution will be robust across all tiers.

Here are a few ways I thought of to try and get to the point where a unique filename could be used:

1) Append the locale string to the bundle name as a parameter on the request. For example, change /jsbundles/mobile.jsto /jsbundles/mobile.js?en_US. However, this does not work - JAWR takes the ?en_US into account and will not serve the bundle at all. The only way this would work is if JAWR could somehow ignore these parameters rather than taking them as part of the bundle name.

2) Create unique bundles for every locale in jawr.properties. This would probably work, but is a maintenance problem, as jawr.properties must be modified each time a new locale is added. Also, if a user dynamically requests a new locale that doesn't have a corresponding bundle, the application will break rather than falling back on a "default" locale.

3) Have JAWR change the outbound file name for any bundle that includes a resource bundle (or perhaps ALL bundles) to append the locale as a parameter to the filename to be requested (mobile.js?locale=en_US)
Posted: September 12, 2012 11:59 by deezer
I made some discoveries after looking at this a bit more.

JAWR does change the file path of the bundle when a bundle of an alternate locale is requested. Therefore the caching of this bundle file is not the issue.

However, it appears that the file jawr_loader.js that is used in the HTML loader version of JAWR cannot be cached anywhere, since it contains a list of the javascript bundles/files to be downloaded. If jawr_loader is allowed to be cached, then the "first" request that fills the cache will have forever have the resource bundles language, random path element of the first request. Once French, always French.

I did think of a few workarounds for this:

Adding a "locale=en_US" parameter to the initial request for the jawr_loader.js (thereby preventing caching multiple locales in the same filename, and forcing the file to be uniquely cached per locale.

Adding the version number of the application to the initial request for jawr_loader.js so that as the application version changes, a new version of jawr_loader.js will be requested by clients.

It would be nice to have some "official" guidance and/or documentation on this.

Replies: 1 - Last Post: September 12, 2012 11:59
by: deezer