<p>Is it possible in a large GWT project, load some portion of JavaScript lazy, on the fly?
   Like overlays. </p>

<p>PS: Iframes is not a solution.</p>

[{'answer_id': 76295, 'author': 'Grant Wagner', 'author_id': 9254, 'author_profile': 'https://Stackoverflow.com/users/9254', 'pm_score': 0, 'selected': False, 'text': '<p>I think this is what you are looking for.</p>\n\n<pre><code>&lt;body onload="onloadHandler();"&gt;\n&lt;script type="text/javascript"&gt;\nfunction onloadHandler() {\n    if (document.createElement &amp;&amp; document.getElementsByTagName) {\n        var script = document.createElement(\'script\');\n        script.type = \'text/javascript\';\n        script.src = \'./test.js\';\n        var heads = document.getElementsByTagName(\'head\');\n        if (heads &amp;&amp; heads[0]) {\n            heads[0].appendChild(script);\n        }\n    }\n}\nfunction iAmReady(theName) {\n   if (\'undefined\' != typeof window[theName]) {\n       window[theName]();\n   }\n}\nfunction test() {\n   // stuff to do when test.js loads\n}        \n&lt;/script&gt;\n</code></pre>\n\n<p>-- test.js</p>\n\n<pre><code>iAmReady(\'test\');\n</code></pre>\n\n<p>Tested and working in Firefox 2, Safari 3.1.2 for Windows, IE 6 and Opera 9.52. I assume up-level versions of those should work as well.</p>\n\n<p>Note that the loading is asynchronous. If you attempt to use a function or variable in the loaded file immediately after calling <code>appendChild()</code> it will most likely fail, that is why I have included a call-back in the loaded script file that forces an initialization function to run when the script is done loading.</p>\n\n<p>You could also just call an internal function at the bottom of the loaded script to do something once it has loaded.</p>\n'}, {'answer_id': 81957, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>GWT doesn't readily support this since all Java code that is (or rather may be) required for the module that you load is compiled into a single JavaScript file. This single JavaScript file can be large but for non-trivial modules it is smaller than the equivalent hand written JavaScript.</p>\n\n<p>Do you have a scenario where the single generated JavaScript file is too large? </p>\n"}, {'answer_id': 82584, 'author': 'Simon Collins', 'author_id': 12412, 'author_profile': 'https://Stackoverflow.com/users/12412', 'pm_score': 0, 'selected': False, 'text': '<p>You could conceivably split your application up into multiple GWT modules but you need to remember that this will limit your ability to share code between modules. So if one module has classes that reference the same class that another module references, the code for the common class will get included twice.</p>\n\n<p>Effectively the modules create their own namespace, similar what you get in Java if you load the same class via two separate class loaders. In fact because the GWT compiler only compiles in the methods that are referenced in your code (i.e it does dead code elimination), it is conceivable that one module will include a different subset of methods from the common class to the other module.</p>\n\n<p>So you have to weigh up whether loading it all as one monolithic module and taking an upfront hit the first time round is better than having multiple modules whose cumulative code size might well be significantly greater than the single module approach.</p>\n\n<p>Given that GWT is designed so that the user should only ever load the same version of a module once (it is cached thereafter), in most cases the one off upfront hit is preferable.</p>\n'}, {'answer_id': 202580, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Try to load a big GWT application with the "one upfront" approach using a iPhone or an iPod touch...it will never load.</p>\n\n<p>The module approach is a but more complexe to manage but better for smaller client devices.</p>\n\n<p>Now, how do I load a module from my Java code without using an iFrame?</p>\n\n<ul>\n<li>Erick</li>\n</ul>\n'}, {'answer_id': 967116, 'author': 'Eric Walker', 'author_id': 61048, 'author_profile': 'https://Stackoverflow.com/users/61048', 'pm_score': 3, 'selected': False, 'text': '<p>Check out <code>GWT.runAsync</code> as well as the Google I/O talk below, which goes into lazy loading of <code>JavaScript</code> in <code>GWT</code> projects.</p>\n\n<ul>\n<li><a href="http://code.google.com/p/google-web-toolkit/wiki/CodeSplitting" rel="nofollow noreferrer">http://code.google.com/p/google-web-toolkit/wiki/CodeSplitting</a></li>\n<li><a href="http://code.google.com/events/io/sessions/GoogleWavePoweredByGWT.html" rel="nofollow noreferrer">http://code.google.com/events/io/sessions/GoogleWavePoweredByGWT.html</a> (around time 25:30)</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/72482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12259/']