I'm currently working on adding HTML5 offline support to my web application, and am mostly following the same approach of mgwt:
- Generate manifest files per permutation at compulation time
- Using a servlet to serve the manifest file, based on the user-agent of the browser.
My question involves step 2: In my servlet, I want to detect which permutation to serve for a certain request. The way I do this now is:
- Get the user agent string from the request
Map this (using simple string operations (e.g.
userAgent.contains("safari")
) to the 'agent id', which I can map using a mapping file to the permutation strong name. In other words, mapMozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)
toie6
, which I can map (using the generated mapping file, see example below) to15B454D690F2CCAD57F1DD809429BF42
.<permutation name="15B454D690F2CCAD57F1DD809429BF42"> <user.agent>ie6</user.agent> </permutation>
The problem I'm facing: I want to use the same method of linking a user agent string to a permutation as GWT uses (i.e. map Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)
to ie6
). This way I don't have to fix my code whenever my GWT gets updated with other permutations/browser versions. In other words, I don't like my current solution of naively matching the complete user agent string in the servlet with the user agent 'id' (in my example 'ie6') in my permutation mapping.
The solutions I thought about were:
- after page load, detect the loaded permutation, and pass that as argument to the servlet. Then after fetching the manifest for that permutation, insert that as an attribute of the html tag using javascript. However, inserting this dynamically does not seem to work properly. (See Dynamically Trigger HTML5 Cache Manifest file? ) (the same post explains a workaround of doing this dynamically using an iframe, but I prefer a cleaner solution)
- somehow use the client-side to map the complete user agent string to a permutation, in my servlet. I'd prefer this solution, but havent found a way to do achieve this... GWT uses javascript to achieve this (see UserAgentPropertyGenerator). I could execute this in my servlet, but this javascript method not only uses the user agent, but uses the dom document as well... Are there other solutions I am overlooking? Surely others must have had this issue as well when creating HTML5 manifest files...