Graceful Degradation When the External Feed Fails
The homepage of kanto-tactics.com says: "Loading the latest ranked data from the game's feed..." But what happens if the game's feed is down? Or rate-limited? Or returning corrupted JSON? A tool site relies on external
The homepage of kanto-tactics.com says: "Loading the latest ranked data from the game's feed..."
But what happens if the game's feed is down? Or rate-limited? Or returning corrupted JSON? A tool site relies on external data, but it cannot break when that data is unavailable.
The Stale-While-Revalidate Pattern
When the app initializes, it shouldn't block rendering waiting for the network. Instead, it should read the last successful feed data from localStorage or IndexedDB. The UI renders instantly with the cached data, showing a subtle "Refreshing..." indicator. Behind the scenes, it fetches the new data, calculates the new rankings, and seamlessly swaps the DOM.
Surfacing Data Freshness
One of the best design choices on the site is printing the "rebuild date" and "rules version" right above the table.
If a fetch fails, the app doesn't show a fatal error screen. It falls back to the cache and explicitly tells the user: "Showing data from yesterday. The feed is currently unreachable." This is a massive UX improvement over a spinner that spins forever. It builds trust because the app is honest about its state.
The Error Queue (__eq) Implementation
As seen in the <head> of the site, there's a lightweight error queue:
window.__eq = [];
window.addEventListener('error', e => window.__eq.push(e));
If the feed parsing fails (e.g., a TypeError because the API changed its JSON schema), this queue catches it. The app can then decide to flush the queue to an analytics endpoint or display a degraded UI state.
A data tool is only as good as its data. Designing for the inevitable moment when that data goes missing is what separates a prototype from a production tool.
The resilient UI is live at kanto-tactics.com.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.