Deploy the GWT Application as a Single JavaScript File

The compiled JavaScript output of the GWT application is divided into various files, for example

  • *. Cache.html
  • *. Gwt.rpc
  • hosted.html
  • *. Nocache.js

...

I know that this is done in order to minimize the size of JavaScript that should be loaded by users. For example, to prevent a Firefox user from loading JavaScript specially compiled for IE6.

However, especially for small GWT applications, it is often faster to upload a single 500 kb file, rather than first making two consecutive requests for a 5kb * .nocache.js script, and then for the rest of the application (cache.html files, etc. )

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

+4
source share
3 answers

Firstly, you can combine all permutations into one file using the so-called "soft permutations" .

Then you can embed * .nocache.js on the HTML host page (for example, using the JSP @include directive) to cut one additional request (you may need to add <meta name=gwt:property content='baseUrl=myapp'> , where myapp is the subfolder where the .nocache files are located.). AFAIK, what Google is doing for its GWT applications.

Alternatively, you can choose server-side permutations if you can completely replace script (* .nocache.js) choices with server-side content matching (based on User-Agent and Accept-Language requests, for example, headers) directly generate the <script> for the corresponding * .cache.js file (if you use the xsiframe linker).

AFAIK, Google uses all these methods for its GWT applications (e.g. Google Groups). However, for a small application, I'm not sure if it is worth the effort ...
In addition, the last two methods work best when your HTML host page is already dynamic and therefore no longer cacheable; otherwise, you are basically moving the problem, not solving it.

I wonder if the sso linker can be used when you reset all properties and soft permutations to one hard permutation.

+4
source

Yes, but it may not be what you want. The answer to this question is: fooobar.com/questions/1401105 / ... in this stackoverflow question: Combine the generated GWT files .

+1
source

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

0
source

Source: https://habr.com/ru/post/1401102/


All Articles