skip to content

For a server-driven home screen in an installed app, what renders on an offline first launch and on an offline relaunch?

level: middleimportance: should knowfreq 24%

answer

  1. never wait on the network to draw
  2. the binary ships one default layout
  3. persist the last layout that rendered
  4. validate before replacing the good copy
  5. layout and content cached separately

basics

~20 s

A bundled default layout covers the first launch, and the last layout that parsed and rendered covers every later one. The app draws that copy at once, with cached or placeholder data, and replaces it only with a newer layout that validates.

solid answer

~50 s

A server-driven screen must never depend on a live response to appear. The binary carries a **bundled default layout**, built only from components that build knows, so a first launch with no network still shows a usable home screen. After each fetch the app persists the layout only once it has parsed and every required component resolves in the registry, so a truncated or invalid response never replaces the **last-good** copy. On relaunch it draws the cached layout immediately and fetches in the background, applying a newer one at a natural boundary rather than under the user's finger. Layout and content are cached separately: prices and stock come from their own cached data, and a section whose data is missing shows placeholders or collapses. After an app update, a cached layout the new build can no longer read gives way to the new bundled default.

code

pseudocode · 15 lines
pseudocode
function show_home_on_launch():
    cached = layout_store.read("home")
    if cached != null and registry.can_render(cached):
        show(cached)
    else:
        show(bundled_default("home"))
    fetch_layout_in_background("home", on_result = accept_if_valid)

function accept_if_valid(response):
    layout = parse(response)
    if layout == null or not registry.can_render(layout):
        log_rejected_layout("home")
        return                      // the last-good copy stays
    layout_store.write("home", layout)
    apply_at_next_boundary(layout)  // not under the user's finger

go deeper

for a junior

Remember the two offline sources: a default layout compiled into the app for the first launch, and the last layout that worked, saved for later launches.

for a middle

Walk the launch sequence and stress validation before the cached copy is replaced, plus keeping layout and content in separate caches.

for a senior

Cover the failure paths: a bad layout deploy, a truncated download, a schema change across an app update, and swapping layouts without moving content under the user.

for a principal

Weigh the bundled default's binary size and staleness against first-launch quality, and decide which screens are worth making server-driven given that offline cost.

## Offline is the first cost of server-driven UI When a screen's arrangement comes from the server, the screen has a new dependency: a network response. An installed app cannot assume one. A grocery app is opened in a store aisle with weak signal, on a train, or for the very first time on a fresh install before any request has succeeded. If the home screen waits for its layout, the user stares at a spinner or an error where the app should be. The design rule is simple to state: **there is always a valid layout on the device before the network is asked for one.** ## The three layouts an app can show | Layout | Where it comes from | When it is used | Risk to manage | |---|---|---|---| | **Bundled default** | Compiled into the binary at release time | First launch, or when no usable cached copy exists | Drifts from current merchandising until the next release | | **Last-good cached** | The most recent fetched layout that validated | Every later launch, online or offline | Must be readable by the current build after an update | | **Freshly fetched** | The layout service, on this launch | Replaces the cached copy once validated | A broken or partial response must never become the cached copy | The bundled default is deliberately plain: it uses only components that build registers and data sources that work from local storage, such as the user's recent orders, so it renders with no network at all. ## The launch sequence 1. Read the cached layout for the screen. If it exists and the build can render it, draw it immediately. 2. Otherwise draw the bundled default. 3. In the background, request the current layout, sending the build's layout schema version. 4. Parse and validate the response against the registry: every required component resolves, every action type is known or safely droppable. 5. Only then write it to storage as the new last-good copy. 6. Apply it at a natural boundary, such as the next visit to the screen or a pull to refresh, rather than rearranging content the user is about to tap. Step 5 is the one candidates skip. Writing the raw response to disk before validation means one bad deploy of the layout service, or one truncated download, replaces a working home screen with a broken one that persists across launches. ## Keeping layout and content apart A layout should describe *what goes where*; the content inside it has its own lifecycle. - **Reference data, don't embed it.** A carousel node names its source (`buy_again`, `weekly_deals`); the items, prices and stock come from the normal data endpoints and their local cache. - **Render with what is there.** Offline, a section whose data is cached renders it; a section with no cached data shows a placeholder of a fixed size, or collapses if the layout marks it optional. - **Keep one source of truth for prices.** A price frozen inside a cached layout would disagree with the product screen the moment the price changes. - **Degrade actions that need the network.** A checkout upsell that adds to a server-side basket can queue the intent or show an offline message, according to the app's offline rules. - **Treat images as content too.** A banner whose image is not cached shows its placeholder colour and title rather than blocking the section. ## After an app update A new build may ship a new layout schema version, and the cached layout was written by the previous build: - **Additive change.** When the schema only gained components and optional props, as it should within a version, the old cached layout still renders. - **Breaking change.** When the new build can no longer read the old copy, the check in step 1 fails and the new bundled default is shown instead. - **Recovery.** The next successful fetch brings a layout assembled for the new version and becomes the last-good copy. - **Cheap check.** Storing the schema version alongside the cached layout lets the build decide without parsing the whole tree. ## Where the edges are How long a cached layout may be shown before it must be revalidated, and how stale-while-revalidate applies, is a cache-freshness decision with its own rules. What this design guarantees is narrower and more basic: whatever freshness policy applies, there is always a layout the current build can draw, and a bad response can never displace it.

  • A fresh layout arrives while the user is scrolling the cached one; do you swap it in immediately?
    Usually not. Rebuilding the tree under a user's finger moves content they were about to tap, a classic source of mis-taps on promotions. Common practice is to apply it at a natural boundary: the next visit to the screen, a pull to refresh, or immediately only if the user has not interacted yet. Sections whose data changed can still refresh in place, because their position does not move.
  • Why not skip the bundled default and show a connect-to-the-internet screen on first launch?
    Because first launch is when a user decides whether the app works, and being offline or on a weak signal at that moment is ordinary for a phone. The bundled default costs some binary size and a refresh each release, but it guarantees a usable screen built only from components that build knows, with no network at all.

  • If the network is down, the server-driven screen can simply show an error state.
  • Write the raw layout response to disk before parsing so a layout is never lost.
  • Embedding prices in the cached layout keeps the offline home screen accurate.
  • A cached layout from the previous build is always readable after an app update.
  • The bundled default can be removed once most users have fetched a layout.