• .NET Developer Tools DevTools

    UI controls for ASP.NET AJAX, MVC, WPF,
    Silverlight, Windows 8 and Windows Phone

  • Hybrid Mobile Development Icenium

    Cross-platform Mobile Development Tool
    with cloud-based architecture

  • HTML5 / JavaScript Development Kendo UI

    Everything you need to build sites and
    mobile apps with JavaScript and HTML5

  • Testing Tools TestStudio

    One easy tool for Functional, Performance,
    Load and Mobile software testing

  • Web Presence Platform Sitefinity CMS

    Everything for your online business - content
    management, ecommerce, emarketing

  • Agile Project Management TeamPulse

    Simple and intuitive project management
    and collaboration software

Contact us

We are here for you.
  • usa+1‒888‒365‒2779
  • uk+44‒20‒7291‒0580
  • bg+359‒2‒8099850
  • de+49‒89‒2441642‒70
  • au+61‒2‒8090‒1465
  • emailsales@telerik.com
Your account Access to your products, updates and support
Telerik Product Families
  • Your Account
    Your Account
    Log in
  • ABOUT US

    About Telerik

    • Company
    • Press Center
    • Customers
    • Community
    • Careers
    • Contacts
Kendo UI - The way of HTML5
Products ▼
Kendo UI Web Kendo UI Mobile Kendo UI DataViz Server Side Wrappers
Demos Purchase Download
Blogs Documentation
Support ▼
Premium Forums StackOverflow Forums
Resources ▼

Featured Resource

Kendo UI Dojo


Blogs Code Library Demos Documentation FAQ Testing
Premium Forums Roadmap User Voice Videos Webinars More Resources
Contact Us Search
 

Blogs

FOUJUI: Flash of Uninitialized JavaScript UI

Thursday, October 06, 2011 by Kendo UI Team Blog | Comments 9

One of the challenges that comes with pure JavaScript UI is a nasty little user experience problem that I'm calling "Flash of Uninitialized JavaScript UI," or FOUJUI (rolls right off the tongue).

FOUJI, similar to FOUC, occurs when:

  • Your rich UI is initialized by JavaScript
  • You rely on JavaScript to render some of your HTML
  • You optimize your site so that scripts run at the end of the page

When an user loads a page that meets these conditions, they briefly see a version of your site that doesn't look correct, as if it hasn't been fully loaded. Styles will be applied, but the UI will look incomplete.

Why?

Let's think about what's happening when you load a site that uses a rich JavaScript front-end (assuming best practice CSS and JavaScript patterns):

  1. The HTML page is requested and loaded (which includes any static HTML in your page)
  2. The external stylesheets referenced by your page are downloaded and the styles are applied to your static HTML
  3. The external JavaScript files referenced by your page are downloaded (this can take some time)
  4. The JavaScript code you've written to initialize your site and UI widgets (usually in a jQuery .ready() handler) is executed
  5. Finally, your site is fully rendered and ready to go!

The problem for users is that your site is "visible" before the initialization code runs to build your JavaScript UI. They see the styled static HTML before JavaScript has the chance to apply the needed transformations to your DOM.

To put this in context, I was having this problem in the Kendo UI Feed Reader demo. The problem was particularly pronounced on devices, like the iPad, where loading and execution of the site JavaScript is slower. Here's what users would see when loading the demo:

SNAGHTML3132a4a

Then, after the site initialization scripts ran and the Kendo UI widgets rendered, users would see the final (proper) site interface:

SNAGHTML314cb4a

Quite a difference! The uninitialized view is usually only visible for a split second (sometimes longer on slower device browsers), so you could easily dismiss this as an ignorable inconvenience. But we want to give our users a better experience. We want to eliminate the FOUJUI.

Solutions to FOUJUI

Solving the Flash of Uninitialized JavaScript UI can be done in a few different ways. The core problem is that the static HTML loaded on the initial request does not represent the final HTML as it will exist after JavaScript modifies the DOM. Solutions:

  1. Render All Initial HTML on the Server
    This is one of the benefits that server-side frameworks, like ASP.NET MVC or PHP, provide. They can render the "initial" HTML on the server and send a "completed" view to browser on the first request. The JavaScript UI initialization still happens and handles all subsequent UI actions, but the initial rendering is sent from the server, skipping the FOUJUI. (This technique can also have theoretical SEO benefits.)
  2. Use a JavaScript Loading Screen
    A loading screen? For the web?! It's not as crazy as it sounds as more of a web application moves to the client. As "web apps" become increasingly like their "native" counterparts, they inherit the challenges native apps have long faced with loading and initialization. Using some simple HTML, CSS, and JavaScript, a JavaScript loading screen can "hide" HTML that's waiting on JavaScript initialization, thus hiding the FOUJUI.

For the Feed Reader demo, everything is happening with static HTML and JavaScript, so option #1 (rendering the initial HTML on the server) is not an option. That means I'll pursue solution #2: a JavaScript loading screen.

Building a JavaScript Loading Screen

There are probably 1,001 ways to build a JavaScript loading screen, but for simplicity, I elected to use some simple HTML and CSS that would cover my entire application while the page is initializing.

HTML

<div id="preLoad">
    <div>
        <img src="styles/BlueOpal/loading-image.gif" alt="Loading Image" style="width:48px;" />
        <br />Loading...
    </div>
</div>

CSS

#preLoad{            
    width:100%;
    height:100%;
    background:#FFF;
    position:absolute;
    top:0;    
}        

#preLoad div{
    position:absolute;
    top: 50%;
    left: 50%;
    height:60px;
    margin-top: -30px;
    margin-left: -24px;
}

Now, when the Feed Reader app loads, rather than seeing the uninitialized HTML (or any of the app, for that matter), users will see my simple loading screen:

SNAGHTML3285fbc

Cool. That's better. Users understand loading screens, and it's a lot less jarring than seeing the FOUJUI effect.

But now I need to make the loading screen "go away" when the JavaScript UI is ready. Doing this requires two changes to my demo:

  1. I need to trigger a new event when the application initialization is done (so I know when to hide the loading screen)
  2. I need to handle the new event and write code to hide my loading screen when it is triggered

Simple enough. In the "init" event for my app (see the source), I add this single line of code that is executed after all initialization steps are complete (including the initialization of my Kendo UI widgets):

//Trigger event indicating init is complete
$(document).trigger("FEED_READER_APP_READY");

And then, to handle this event when it's triggered, I wire-up a binding in my main page that will hide my loading screen:

$(document).bind("FEED_READER_APP_READY",function(){ 
    $("#preLoad").fadeOut(); 
});

And that's that. Now users will always see the loading screen while my app is initializing, and when the UI is ready, the loading screen will fade out to reveal a ready-to-work application. No FOUJUI!

Improving the Effect with CSS3 Transitions

While the functional problem has been solved at this point, I quickly discovered that the jQuery "fadeOut" animation (which uses JavaScript) does not work well on all devices. The animation is choppy (at best) on mobile devices due to the weaker JavaScript processing.

We can improve this effect and make it buttery smooth on all devices by leveraging CSS3 Transitions. Browsers hardware accelerate CSS animations/transitions, giving CSS3 the power to speed-up any app (especially on mobile devices).

Browser support for CSS3 transitions is strong, but even browsers that don't support transitions will gracefully degrade to a functional, "direct" transition. So there's no reason not to use this technique.

Adding the Transition

The first step in this refactoring is to add the cross-browser CSS3 rules that define my transition. To achieve the same "fade out" effect, I will use the CSS opacity and visibility settings to hide my loading screen.

#preLoad{            
    width:100%;
    height:100%;
    background:#FFF;
    position:absolute;
    top:0;    
    
    -moz-transition: visibility 0s linear 1s, opacity 1s ease-in-out 0s;
    -webkit-transition: visibility 0s linear 1s, opacity 1s ease-in-out 0s;        
    -o-transition: visibility 0s linear 1s, opacity 1s ease-in-out 0s;
    transition: visibility 0s linear 1s, opacity 1s ease-in-out 0s;
}

This code basically says:

  • When "visibility" value is changed, change to the new value in 0s after a 1s delay
  • When "opacity" value is changed, change to the new value in 1s after a 0s delay

If opacity is used without visibility, then the entire app would remain "blocked" by the an invisible element after the loading screen fades out (opacity=0). By combining with visibility, the loading screen will fade out and be properly hidden. The delay ensures the opacity change animation will complete before the element is hidden.

Starting the Fade Out Transition

How do we trigger the CSS3 fade out transition? By simply changing the CSS opacity and visibility properties to their desired target values on our loading screen element:

$(document).bind("FEED_READER_APP_READY",function(){ 
    $("#preLoad").css("opacity","0").css("visibility","hidden"); 
});

When these values change, the browser will calculate the necessary animated transition to get from the original values to the new values, using the specified timing function ("ease-in-out") to shape the animation path.

The result: a fade out transition that looks smooth on desktop and mobile browsers.

The Final Result: No More FOUJUI

With these simple techniques applied, our user experience is now much better. When the application loads, users briefly see a loading screen, hiding the uninitialized HTML UI, and then a smooth, animated transition presents the app when it's ready.

You can try the updated Kendo UI Feed Reader demo for yourself to see this in action.

For those of you using a version of Internet Explorer less than 10 (the first from Microsoft to support CSS3 Transitions), here is a quick animated example showing what other browsers are seeing (in rough animated GIF format):

kendoui-feed-reader-foujui

The transition to JavaScript-driven applications will increasingly require developers to adopt "new" techniques to deliver premium user experiences. Eliminating the disruptive FOUJUI is one such problem that can easily be solved with minimal modification and code. Hopefully this post gives you some ideas for improving your own JavaScript application experiences, and hopefully you'll join me in eliminating FOUJUI!

About the Author
Todd Anglin is an avid HTML5, CSS3, and JavaScript advocate, and geek about all things web development. He is an active speaker and author, helping developers around the world learn and adopt HTML5. Todd works for Telerik as Chief Evangelist where his current technical focus is on Kendo UI. Todd is @toddanglin on Twitter.

9 Comments

  1. 1 Vesselin Obreshkov 06 Oct 2011
    Thank you for this great article. I'm actually myself just getting deeper and deeper into a JavaScript-heavy  web / intranet app and I'm starting to get those exact side effects even on our development machine so I can only imagine how things would go from here, particularly moving to production. This loader, I think is an ideal solution (server pre-loading has it's benefits too though). Copy / pasted ;)
  2. 2 Sean Palmer 06 Oct 2011
    What do you think of setting body {visibility:hidden} and then only showing it when everything is loaded?
  3. 3 Todd 06 Oct 2011
    @Vesselin- Great. Glad the post is helpful!

    @Sean- Interesting idea. The downside to that approach is that they user gets no indication that the app is working. They just see a blank screen for a longer period of time, which is probably not desirable. So you'd have to use body visibility changing + some kind of loading indicator. Why double the effort?
  4. 4 Paul Irish 06 Oct 2011
    I think its best to have CSS in place that minimizes this effect.

    You can assume js is enabled and your CSS can reflect that. Use the no-js/js technique at http://paulirish.com/2009/avoiding-the-fouc-v3/ for this

    For js-based panel layout these seems harder, but in an ideal world there could be a build step to maximize the UI being in place when the app starts. Google Calendar is like this.. the UI is all set from CSS and then JS hops in and wires it up

  5. 5 Todd 06 Oct 2011
    @Paul- Correct me if I'm wrong, but that sounds a bit more like Solution #2: creating the necessary "initial state" HTML server side (either dynamically at run time or during a build process) to avoid the FOUJUI (a somewhat separate problem from FOUC).

    When you've got a JS UI (and you don't have a build process/server process "pre-rendering" the start-up HTML) then the No-JS/JS technique does not apply. You could use it, but would it have much advantage over loading element?

    To your point: Yes, in an ideal production word, you'd probably want to have as much of your initial HTML generated for first load so JS is just wiring-up behavior.
  6. 6 Steve 06 Oct 2011
    One has to wonder if using JS to render HTML will be a mistake, given the popularity of proxy browsers like Opera Mini and the emergence of Amazon Silk.
  7. 7 Luca 08 Oct 2011
    Todd,
    why not just using the :empty pseudo-class on a container element?
    Something like this https://gist.github.com/1272149
  8. 8 Kyle Simpson 10 Oct 2011
    I named this "FUBC" (foo-bic: flash of unbehaviored content) a couple of years ago, when talking about how script loaders (like <a href="http://labjs.com">LABjs</a>) can cause this effect. Here's where I describe it:

    <a href="http://labjs.com/#fubc">LABjs: FUBC</a>

    Anyway, glad to see others calling attention to this UX issue. :)
  9. 9 Todd 10 Oct 2011
    @Luca- Aside from missing support in IE7/8 for :empty, it also wouldn't solve the right problem. With FOUJUI, there is content in the page. It's not empty (per the CSS definition). Rather, we have content that is not properly initialized by JS that we want to "hide" from our users so they don't see the "pre-initialized" state of our HTML.

    @Kyle- Thanks for sharing another resource on this issue!

Comment

  1. Click to add

  2. Click to add

  3. Click to add

  4.    
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
      
       
Blogs feed
Categories

  • Tutorials (26)
  • Release (33)
  • Browsers (7)
  • Extensions (3)
  • Tip of the Week (10)
  • Videos (5)
  • Concepts and Theory (13)
  • Misc. (25)
  • Framework Constructs (6)
  • Mobile (6)
  • UI Widgets (5)
  • Blogs (1)
Archive
  • 2013 May (7)
  • 2013 April (10)
  • 2013 March (9)
  • 2013 February (12)
  • 2013 January (10)
  • 2012 December (9)
  • 2012 November (11)
  • 2012 October (6)
  • 2012 September (7)
  • 2012 August (8)
  • 2012 July (10)
  • 2012 June (8)
  • 2012 May (10)
  • 2012 April (7)
  • 2012 March (13)
  • 2012 February (10)
  • 2012 January (6)
  • 2011 December (10)
  • 2011 November (4)
  • 2011 October (6)
  • 2011 September (5)
  • 2011 August (9)
Home Web Mobile DataViz Server Wrappers Whitepapers Surveys Chrome Icenium Contact Us

Kendo UI framework is developed by Telerik - a leading provider of UI components for web, desktop and mobile applications. Trusted by over 100,000 customers worldwide for our devotion to quality and industry-best technical support, Telerik helps professionals maximize their productivity and "deliver more than expected" every day.

kendoui - powered by html5, css3 & jquery
get social
  • Twitter
  • Facebook
  • Google plus
  • RSS
Privacy Policy | Branding Guidelines
Powered by Sitefinity CMS

Copyright © 2011 - 2013 Telerik Inc. All rights reserved.