Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content disappears for fraction of a second on offline web app load

I've observed this on iOS 4.3 to 5.0. When you create a even a simple offline web app, meaning one HTML file + few assets such as CSS and JS (all present in the cache manifest), it works offline (I tested in Airplane Mode) – BUT, when you add such an app to your home screen and open it in fullscreen mode, it first displays initial content, then everything disappears (page becomes white) for half a second or more, then content reappears again.

You can see this by adding Glyphboard, a well-known and useful offline web app, to your iOS home screen and launching it a few times. You should see the white flash effect every time you load it.

This is a big problem because it gives away the non-nativeness of an app and gives the impression that the app is non-optimized for performance and buggy.

I've tried finding reports about this but all I can find is rumors and misconceptions about the iOS 4.3 JavaScript rendering engine fiasco, which doesn't need at all be related to this issue. But in iOS version 3 I distincly remember not ever seeing the white flash.

like image 789
mislav Avatar asked Sep 23 '11 22:09

mislav


3 Answers

Clearing the screen and other artifacts while rendering is a common issue of HTML rendering due to the progressive nature of HTML. The concept is that the browser should draw as early and often as possible and render styles/scripts/content as they become available. It's possible the markup has an issue where all rendering is delayed until some content or a script is available. This could happen if:

  • You have dynamic heights based on image dimensions but you haven't set the image dimensions in the markup or CSS.
  • Your layout is based on tables and you aren't using 'table-layout:fixed` in CSS.
  • Your HTML uses inline scripts with document.write().
  • You have some kind of onLoad() function that reveals/modifies content.
  • You link to an external stylesheet.
  • You're using uncacheable external content or you've disabled caching.
  • You're using external content that's returning 404 or isn't available offline.

Has your HTML/CSS changed between testing IOS versions?

like image 104
SpliFF Avatar answered Nov 04 '22 11:11

SpliFF


I've found this to be caused by the use of:

<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0"> 

With a minimal page, I get a white flash between the apple-touch-startup-image and the page contents if I use the viewport meta tag. If I take out the tag, no flash.

It's possible to work around the problem by setting the tag programatically.

like image 23
Paul Greyson Avatar answered Nov 04 '22 10:11

Paul Greyson


I think what happens here is that iOS takes a screenshot from the page when it is added to the main menu. Then this screenshot is displayed during the application loads (WebKit loads). WebKit starts rendering the page and the page itself is constructed in such a way that the page content is not instantly available, leading to a white flash which is a rendered page when page content is not yet there,

You can avoid the problem to a certain level by building your JS/CSS so that it loads the initial HTML view fast and then lazily loads / builds the rest of the resources on the background. Also you can set a custom loading screen instead of the default screenshot iOS uses from the page.

Maybe if you can take yourself a screenshot of your app and then have something like this:

 <body style="background: white url('my-initial-loading-screen.png')" />

... and make sure image is available and comes from manifest.

Or even better, have loading screen which does not require any external resources to show (just plain HTML) so you know the browser doesn't need to load anything.

like image 30
Mikko Ohtamaa Avatar answered Nov 04 '22 11:11

Mikko Ohtamaa