Case Study · Offline-First Web App
Offline-First Field Data PWA for Conservation Teams
Replacing a quota-limited form platform with an installable, zero-dependency Progressive Web App using IndexedDB, Cloudflare Pages, and self-hosted n8n webhooks.
- HTML5 / CSS3 / Vanilla JS
- IndexedDB
- Service Worker
- Cloudflare Pages
- n8n Webhooks
- Google Drive & Sheets
1. The Challenge
Field officers conducting community meetings, workshops, and site visits across remote villages in Botswana’s Okavango Panhandle operate without cellular coverage most of the time. Their previous workflow relied on KoboToolbox, which introduced three recurring bottlenecks:
- Media storage caps: Attaching up to five field photos plus scanned attendance registers and meeting minutes quickly exhausted free-tier storage quotas.
- Shared account friction: Officers had to manage shared logins across multiple devices and manually pull submissions down once back online.
- Rigid form UX: Standard form wrappers struggled with bright outdoor sunlight, small tap targets on budget Android phones, and bilingual English/Setswana prompts.
2. System Architecture
Rather than locking the organization into another SaaS subscription, I separated the mobile capture interface from the storage backend. The app is a pure static PWA hosted on Cloudflare Pages, talking to two lightweight webhook endpoints powered by self-hosted n8n:
- Edge Delivery & Offline Cache (Cloudflare Pages + Service Worker): A Web App Manifest and Service Worker cache the entire HTML, CSS, and JS bundle on first load so the app launches full-screen in Airplane Mode with zero network dependency.
- High-Capacity Local Queue (IndexedDB): Drafts, compressed photos, PDF/image registers, and queued reports are persisted asynchronously in native IndexedDB until the officer returns to base camp.
- Authenticated Sync & Routing (Cloudflare Tunnel → n8n): When back in range, a manual “Sync Pending Reports” action posts each queued payload over HTTPS with a custom authentication header. n8n unpacks binary attachments to Google Drive and logs structured rows to Google Sheets with last-write-wins deduplication by unique Record ID.
- Dynamic HQ Reference Lists (GET Webhook): A second read-only webhook pulls live staff, donor, village, department, and activity lists from Head Office spreadsheets and caches them locally—eliminating code redeploys whenever rosters change.
3. Key Engineering Decisions
Migrating from localStorage to IndexedDB
The initial prototype stored drafts and base64-encoded photos in localStorage. Because browsers cap localStorage at roughly 5 MB—and base64 encoding inflates binary files by ~33%—queuing just three or four photo-heavy meetings risked triggering a QuotaExceededError in the field.
Refactoring persistence to a lightweight, zero-dependency IndexedDB wrapper expanded offline capacity to hundreds of megabytes while moving writes off the main thread so low-RAM Android devices stay responsive. Tiny synchronous config keys (device activation state, device ID, and cached HQ catalogs) remained in localStorage for instant startup hydration.
Frictionless Onboarding & Webhook Security
Field staff shouldn’t need individual user accounts just to submit meeting notes. Devices activate once via a QR code or URL token (?key=<token>) that saves the credential locally and immediately strips the parameter from the browser’s address bar via history.replaceState(). Outbound sync requests pass that key in a custom HTTP header verified by n8n, allowing Cloudflare Access to keep internal editor UIs locked behind OAuth while letting authenticated field syncs pass cleanly.
Field-First UX & Branching Logic
- Sunlight readability: High-contrast color tokens and minimum 48×48 dp tap targets prevent mis-taps in bright outdoor glare.
- Adaptive workflow: Selecting an internal vs. external meeting organizer dynamically switches between a full 4-step stepper and a condensed capture flow, auto-calculating attendance totals across age and gender brackets.
- Bilingual toggle: Built-in English and Setswana labels help staff complete fields accurately without leaving the page.
Storage-Agnostic Handoff: Because the mobile app only speaks standard JSON over HTTP, the destination can be swapped inside n8n—from Google Drive and Sheets to Microsoft OneDrive/Excel, a SQL database, or a serverless Google Apps Script inside the organization’s own account—without touching a single line of frontend code.
4. Lessons Learned
- Watch for Cloudflare Pages 308 redirects in PWAs: Cloudflare Pages automatically 308-redirects
/index.htmlto/. Pointingmanifest.json("start_url": "./") and the Service Worker navigation cache to./instead of./index.htmlprevents Android Chrome from rejecting cached redirected responses when launching offline. - Delayed Sync beats background magic: Giving field officers an explicit sync button with clear pending/synced status badges eliminates silent background failures on flaky rural connections and preserves battery life.
- Decouple frontend and backend repos: Keeping the static PWA in its own clean repository (with n8n workflow exports version-controlled in a separate private backend repo) makes Cloudflare Pages deployments instantaneous and keeps operational configs out of public builds.
