Posted: September 11, 2012 12:15 by deezer
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> <script> JAWR.loader.script('/jsbundles/mobile.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)