English 中文(简体)
How to prevent GWT onload flicker in the Web Application Starter Project?
原标题:

I m new to GWT, and I m sure this is answered in SO somewhere but I ve yet to find

I downloaded the GWT 2.0 eclipse plugin, and was pleased to see it comes with a starter project.

However, I was surprised that when running it, there is an unpleasent flickering...

  1. The text loads without the CSS first
  2. It takes a while untill the select box apears

(If you don t see the flicker, try and press F5 to refresh)

All mature GWT apps seem to have a loader before that but I didn t find an easy, standard way to add it.

It seems this app loads in this order: (correct me please if I mixed it up, its only my guess)

  • Basic layout HTML,
  • All JavaScript, and CSS
  • Runs the logic on the "onload" event (soonest time your compiled javaScript can start - ?)

So I can t programmatically add a loading spinner before GWT was loaded, a bit of a catch 22 for me

Am I missing something basic? is there a best practice way to add that initial spinner?

I was thinking simply adding a div with an animated gif, and in the onload event - hide it.

But I m sure there is something better.

Let me know if this is a duplicate question


Update: found this related question, not answering mine though...

最佳回答

I ve handled this problem before by not using the GWT module to load CSS, but loading it directly in the tag itself. If you do this, the browser will always load the CSS first, even before the GWT JS is loaded.

This means you ll lose a bit of flexibility and speed, but its the only workaround I ve used so far.

EDIT: Extra info cause I want the bounty :D

If you do not remove the <inherits name= com.google.gwt.user.theme.standard.Standard /> from your module.gwt.xml file, then the GWT standard theme is loaded in the JS file that GWT creates. This JS file loads after the HTML page renders, and injects the CSS after load. Hence the flicker.

To avoid the flicker, you can comment out that line and insert your own stylesheet into the <head> of your HTML file. This ensures your CSS loads before the HTML renders, avoiding any flicker. If you really want the GWT theme, you get it out of the source code.

To use a spinner with GWT is quite easy. One simple way would be to keep it in a div with an id in the HTML file itself. Then, in the onModuleLoad(), simply hide that div by calling RootPanel.get("spinner").setVisible(false);

That should show the spinner till GWT loads itself.

问题回答

Here s what we do to implement a spinner.

You put something like the following HTML just below the script line that loads your application (ie. the one with nocache.js). e.g.:

    <div id="loading">
        <div id="loading-msg">
            <img src="icons/loading-page.gif" lt="loading">
            <span>Loading the application, please wait...</span>
        </div>    
    </div>

Then in your application EntryPoint you reach into the page using the DOM and remove that div. e.g.

final RootPanel loading = RootPanel.get("loading");
if (loading != null) {
    DOM.removeChild(RootPanel.getBodyElement(),
                    loading.getElement());
}

Ehrann: I m afraid the practice mentioned in the above answers is the only way for now. GWT doesn t provide similar features to show/hide a "loading" frame "on the fly". I guess one of the reason is that this requirement is not so "common" for all GWT users, one person might want a very different style of the "loading" than others. So you have to do that by yourself.

You can have a look at the GXT showcase page (based on GWT too): http://www.extjs.com/explorer/ for how they do that. For the source of it, download Ext GWT 2.1.0 SDK here: http://www.extjs.com/products/gxt/download.php and check the samples/explorer folder after extracting it. For details see the edit below:

EDIT

Check the source code for http://www.extjs.com/examples/explorer.html and you can see a div with id "loading". For each samples (extending Viewport), GXT.hideLoadingPanel(loadingPanelId) is called in onAttach() (the initialization), which hides the loading frame.

Check source code of Viewport here

Check source code of GXT.hideLoadingPanel here

You can do it in a similar way.

You could put an HTML loading message in the host page (use style attributes or embed the style tag in the header to make sure that it s styled), and remove the message once your modules has loaded, e. g. Document.get().getBody() with .setInnerHTML("") or .removeChild(), and then present your application programmatically however you want.





相关问题
Refresh the UI in gwt

I have created some custom composite widget, which listens to an events (in my case loginEvent). Once the event is caught the state of the widget changes so as the way it should look (in my case I ...

How to create a development/debug and production setup

I recently deployed inadvertently a debug version of our game typrX (typing races at www.typrx.com - try it it s fun). It was quickly corrected but I know it may happen again. After digging on ...

GWT error at runtime: ....style_0 is null

My code works fine in IE 8, but on firefox 3.5, the javascript fails to load. I used firebug to figure out why, and the error I get is (GWT detailed mode) My suspicion is that some style is not ...

GWT s hosted mode not working

I ve been stumped for a while trying to figure out why my GWT demo app isn t working in hosted mode so I went back and downloaded the Google Web Toolkit again, unzipped it and simply went to the ...

How to disable Google Visualizations Tool Tips?

Does anyone know how to disable the tool-tip boxes that popup when a Google Visualizations chart is clicked (Selected)? Following the sample code at Getting Started with Visualizations, the "...

GWT 2 CssResource how to

I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and ...

热门标签