Free Screenly Player with every Business or Enterprise yearly plan. How it works →

August 1, 2026

Edge Apps can keep showing the last good data when a fetch fails

A weather app on a lobby screen that loses its API for 10 minutes has 2 choices: show an error to everyone walking past, or keep showing the last forecast it had. writeEdgeAppCache() and readEdgeAppCache() make the second one a few lines of code:

import {
  getSettingWithDefault,
  readEdgeAppCache,
  writeEdgeAppCache,
} from '@screenly/edge-apps'

async function loadWeather() {
  try {
    const response = await fetch(weatherApiUrl)
    if (!response.ok) throw new Error(`Weather API returned ${response.status}`)

    const weather = await response.json()
    writeEdgeAppCache('weather-app', 'forecast', weather)
    return weather
  } catch (error) {
    if (getSettingWithDefault('display_errors', false)) throw error
    return readEdgeAppCache('weather-app', 'forecast')
  }
}

Values are stored in the player’s localStorage as JSON under namespace:key, so 2 apps, or 2 caches in one app, don’t overwrite each other. Anything JSON can hold works as a value.

The cache is for fallback, not freshness. Nothing expires, so read it only after a real failure, and expect it to be empty after the player restarts. Both functions fail quietly: readEdgeAppCache() returns null when there’s nothing usable, and writeEdgeAppCache() does nothing when storage is full or unavailable, so neither needs its own try.