Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:49:45+00:00 2026-05-27T19:49:45+00:00

I have some external Javascript files in my GWT app that I only want

  • 0

I have some external Javascript files in my GWT app that I only want to download when the user accesses the section that requires them. I included the JS files in a UiBinder page like so:

<g:HTMLPanel>
    <script src="blah.js"/>
</g:HTMLPanel>

The files won’t necessarily be downloaded as soon as the view is loaded, so when I load the view, I check for an exception indicating that the external code isn’t accessible and try again until the view can be created without an exception.

This works in Firefox but it doesn’t work in IE7/IE8. I used AJAX Edition to trace what’s happening in IE, and a request for the file is made but it doesn’t download anything, the size is 0. The web server access logs don’t show that the file was requested.

Any idea what’s going on?

Or is there a better way to do this? The investigating I’ve done thus far does not indicate that GWT has a convenient way to do this.

Update:

Although we’re not on 2.4 yet, just to try I copied in the source files needed for ScriptInjector and attempted to use that per the suggestion by Thomas. The JS files download correctly in both browsers, but I get the ‘$wnd.xxxx is undefined’ exception indicating that the references in the external script can’t be found. I don’t try to load my widget until the onSuccess() call returns from the script inject – so my code looks something like this:

ScriptInjector.fromUrl("../xxxx.js").setCallback( 
      new Callback<Void, Exception>() { 
         public void onFailure(Exception reason) { 
           Window.alert("Script load failed."); 
         } 
         public void onSuccess(Void result) { 
           Window.alert("Script load success."); 
           MyWidget widget = new MyWidget(); 
           client.onSuccess(widget); // adds the widget to the view 
         } 
      }).inject(); 

I also don’t see the JS file references added to the DOM in Firebug, but I wonder if that is because they are being added to the DOM of the GWT portion of the page, not to the actual index.jsp.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:49:45+00:00Added an answer on May 27, 2026 at 7:49 pm

    you need to tell the ScriptInjector to add the script to the top level window.

    ScriptInjector.fromUrl(scriptUrl)
        .setWindow(ScriptInjector.TOP_WINDOW)
        .setCallback(new Callback<Void, Exception>() {
            @Override
            public void onSuccess(Void result) {
                //script loaded OK
            }
    
            @Override
            public void onFailure(Exception reason) {
                //TODO script injection failed
            }
        }).inject();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an external javascript file that I want to, upon include, write some
I have a flash movie that requires some JavaScript from an include file but
I have some jQuery code in an external Javascript file that is making an
I have some constants in JavaScript that I'd like to reuse in several files
I have some external header files in a separate directory (its the sqlite3.h). I
Does Google read external Javascript Files that are included? If I were to append
I have found utilities that can compress html, javascript, and css files individually. However,
How can one set character encoding on external JavaScript files using only Websphere (5.1)?
I have an external JavaScript file that will be used on pages with lots
We have that Flex app talking to the server. We need some kind of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.