Server Side Script Selection

31 views
Skip to first unread message

Sanjay

unread,
Jul 16, 2011, 6:31:54 PM7/16/11
to google-we...@googlegroups.com
Hi,

Server side script selection would solve a number of problems for us. First, it would allow us to transparently make deferred binding decisions based on data we have saved for the current user, ie pick locale, theme, and role, as opposed to doing the same thing via HTML meta tags, which is messy (and might offer a small security vulnerability*). Second, since we have to do user agent sniffing on the server to warn older browsers about potential display issues, we can find both user.agent and formfactor settings from the UA string. Third, this will eliminate the If-Modified-Since checks for the client side selection script, improving page load time by atleast 100ms but usually closer to 150ms (with a primed cache). Also, as a performance geek, that extra HTTP request really really bothers me :)

I already have a linker in place to map permutation variables to an MD5 strong name inspired by the conversation here. The resulting file has a lot of rows looking something like this:
safari-en_CA-user-elegant-desktop=E4BD0CBC2D17355D08286E7CF79FF120 

So I can easily determine which script I need to serve. The only thing is I'm not sure how I actually serve the script file. I'm also not sure if the selection script does anything more than just load the file.

Is it just a matter of my jsp generating this in the html:
<iframe src="<Correct MD5 name here>.cache.html" style="<hide frame>">
</iframe>

Javascript isn't really my thing, so the things I've seen in the client side selection script are fairly confusing. So, in summary, my questions are as follows:

1) What HTML do I generate to serve the code file after determining which one is appropriate?
2) Does the selection script set up state thats later used by the downloaded code file?
3) Would the iframe snippet I have above work, or fail epically?
4) If I figure out Question 1, can I use the same method to serve "hosted.html", thus keeping dev mode working, or would I need to maintain my javascript property providers?


* I'd really prefer if we didn't expose things like <meta name='gwt:property' content='role=user'/> in our html that we send down though. This isn't actually a security hole, because all of our exposed service endpoints on the server check roles anyways, just a cleanliness issue more than anything. Changing this value might allow users to look at admin ui, but won't let them view/change anything.

Sanjay

unread,
Jul 17, 2011, 4:21:12 PM7/17/11
to google-we...@googlegroups.com
Sorry for bumping, but I have an update.

After spending some time researching this topic, it seems to me that the most appropriate way to accomplish server side script selection is to write a new primary linker. These seem to support a lot of functionality that I don't need (like including the css and js files from the .gwt.xml file), so I don't really need to support that. While our project doesn't use code splitting right now, its a definite possiblity in the future.

I wrote a fairly trivial primary linker that simply emits the compilation result javascript to a .cache.js file (currently only the first element in the js array returned by getJavascript(), will look into adding runAsync support later). I tried including the resulting file directly in a script tag, but that didn't work. I defined the $wnd, $doc, and $stats variables. I appended a call to $wnd.gwtOnLoad, but am not entirely sure how to get the errFn variable, or the soft permutation id for that matter. I'm currently leaving those at null and 0 and that seems to work, but I think this is getting rid of my global exception handler.

For anyone familiar with the linker system, where do I get errFn or softPermutationId for gwtOnLoad?

Also, my readings of javadoc seem to indicate all I have to do to support runAsync is provide __gwtStartLoadingFragment and __gwtInstallCode. Is that really all I have to do?

2nd last question: will this scheme handle ClientBundle, or more accurately ImageBundle?

Last question: could I support dev mode in this configuration? I was thinking if I detect devmode I would link to a seperate js file like the one here. Would that work?
Reply all
Reply to author
Forward
0 new messages