mxro
mxro

Reputation: 6878

Deploy GWT Application as Single JavaScript File

The compiled JavaScript output of a GWT application is divided into various files, for instance

...

I know this is done with the purpose of minimizing the size of the JavaScript, which has to be downloaded by users. For instance so that a Firefox user does not have to load the JavaScript specifically compiled for IE6.

However, especially for small GWT applications it might often be faster to download a single file of say 500kb rather than make two sequential requests first for the 5kb *.nocache.js script and then for the rest of the app (cache.html files, etc.).

This leads me to the question: Is there any framework or procedure to bundle the output of the GWT compiler into a single JavaScript file?

Upvotes: 4

Views: 2063

Answers (3)

mxro
mxro

Reputation: 6878

I found another way to accomplish this: Writing a custom Linker for GWT. Two examples for linkers which compile into a single JavaScript file are:

Upvotes: 0

Thomas Broyer
Thomas Broyer

Reputation: 64541

First, you can merge all permutations in a single file by using so-called "soft permutations".

Then, you can inline your *.nocache.js into the HTML host page (e.g. using a JSP's @include directive) to cut one additional request (you might have to add a <meta name=gwt:property content='baseUrl=myapp'> where myapp is the subfolder where the .nocache. files are located).
AFAIK that's what Google are doing for their GWT apps.

Alternatively, you can run the permutation selection on the server-side if you can totally replace the selection script (*.nocache.js) with server-side content negotiation (based on User-Agent and Accept-Language request headers for instance) that can directly generates a <script> tag for the appropriate *.cache.js file (provided you use the xsiframe linker).

AFAIK, Google use all these techniques for their GWT apps (such as Google Groups). For a small app, though, I'm not sure it's worth the effort…
Also, the last two techniques work best when your HTML host page is already dynamic and therefore already non-cacheable; otherwise you're mostly moving the problem, not solving it.

I wonder whether the sso linker can be used when you collapse all properties and soft-permutations down to a single hard permutation.

Upvotes: 4

Hilbrand Bouwkamp
Hilbrand Bouwkamp

Reputation: 13519

Yes, but it's maybe not something you want. See this answer: https://stackoverflow.com/a/4453716/66416 to this stackoverflow question: Merge GWT generated files.

Upvotes: 1

Related Questions