Getting data onto a screen is the easy part. Ensuring data integrity and robust API caching strategies for public info screens, however, is a different challenge entirely.
Recently, I performed a significant refactoring of both the backend logic (PHP) and frontend display (JavaScript) for the digital signage solution I developed for Østfoldmuseene. Here is how I solved critical challenges regarding data integrity and fault tolerance.
The Problem: When Date Ranges Lie
The challenge began with a logical flaw in how the system interpreted opening hours. The external API provided data ranges that didn’t account for specific closed days (like “Closed on Tuesdays”).
My original code simply validated dates. To fix this, I had to rewrite the PHP logic to implement stricter validation.
The Solution: Implementing API Caching Strategies
One of the most critical aspects of this update was improving how we handle data fetching. Reliable API caching strategies are essential when building displays that cannot afford downtime.
I noticed the API returned separate objects for different time periods. I solved this by aggregating the data server-side. By iterating through the API response and merging time slots, I now send a single, structured JSON object to the frontend.
Zero Downtime with Stale-While-Revalidate
Stability is critical. Previously, the system would show an error if the network dropped. To solve this, I implemented advanced API caching strategies inspired by the stale-while-revalidate principle.
-
The system attempts to fetch fresh data.
-
On Success: It updates the local cache.
-
On Failure: It serves the cached version instead of crashing.
This ensures 100% content uptime, proving that smart API caching strategies are just as important as the visual code.
Frontend: Performance and Race Conditions
On the client side, I discovered a race condition where the text resizing function calculated dimensions before the web font loaded. I solved this using Promises and the document.fonts.ready API.
Summary
Through this iteration, I transformed a simple script into a robust application. Mastering API caching strategies and complex date logic resulted in a solution that is smarter, more efficient, and far more resilient in production.


Comments (0)