Execution order of cache.js versus other script tags

83 views
Skip to first unread message

Andrew Buck

unread,
Dec 10, 2019, 1:53:25 PM12/10/19
to GWT Users
My GWT code uses a an external javascript library through JsInterop and I want that library to download in parallel with my cache.js file, but execute before the cache.js file does. The problem is that the nocache.js injects the cache.js file into the page and any injected script tags are automatically loaded as async rather than defer, which means that if the cache.js file download finishes prior to the library, it will be executed first. Is there a way to download cache.js in parallel, but stop cache.js file from executing until other script tags have executed?

The code below is what I currently have. It guarantees that the execution order will correct, but the cache.js file won't even be injected and begin downloading until the library js file has downloaded and executed, which makes the page load much slower than if the cache.js file were downloaded in parallel with library.js.

<html>
   
<head>
       
<script defer src="library.js"></script>
       
<script defer src="myproject.nocache.js" ></script>
   
<head>
...
</html>




Jens

unread,
Dec 11, 2019, 5:45:30 AM12/11/19
to GWT Users
Usually you would use GWT's ScriptInjector together with ClientBundle + TextResource/ExternalTextResource. That way you can either embed your external JS into the GWT JS (TextResource) so it downloads as part of your app download or you let the GWT app asynchronously download the JS when needed (ExternalTextResource).

You can also use GWTs XML modules to include additional scripts which will be loaded before your entry point starts. But it could be that it won't be compatible with future GWT versions based on J2CL. http://www.gwtproject.org/doc/latest/DevGuideOrganizingProjects.html#DevGuideAutomaticResourceInclusion

-- J.

Andrew Buck

unread,
Dec 11, 2019, 3:56:19 PM12/11/19
to GWT Users
Thanks!
Reply all
Reply to author
Forward
0 new messages