Offline-first software defines which work remains useful, what data can be held safely on the device, how pending actions are shown, and how the server reconciles them later. Reading a cached page is different from completing a field job or booking. Payments, regulatory submissions, and decisions that depend on live stock may still require verification.
An offline-first progressive web app (PWA) defines useful work without a connection, stores the minimum safe local data, records user intent durably, and reconciles it when the network returns. The browser gives you three building blocks. A service worker caches files and handles requests. IndexedDB keeps records on the device. In some browsers, Background Sync sends queued work when the connection returns.
None of them guarantees storage space, data persistence or background execution. Design for storage pressure, shared devices, expired sessions, upgrades and conflicts from day one.
We build and run ClinicTek, a clinic management system with an installable web app for clinic staff and a patient portal that patients open from a link. We also built an offline-first app for craftspeople on Herafy GEE, our client's marketplace. The examples below come from that work, with ClinicTek's code as of November 2026.
Observe the disconnected moment
Follow the user where connectivity actually fails. A field technician may need assigned jobs, an address, a checklist, notes, and photos. Reception may need today’s schedule. A cashier may need to record an order without creating it twice later. Classify every action as offline-capable, recent read-only, or connection-required. The boundary should follow business risk and data sensitivity, not the easiest technical demo.
Here is that classification for four roles. The doctor row is how ClinicTek works; the others are illustrations.
| Role | Works on the device | Read from the last saved copy | Needs a confirmed connection |
|---|---|---|---|
| Field technician | Checklist, notes, photos, customer signature | Job details and address | Taking an electronic payment |
| Receptionist | A note on an appointment | Today's schedule and contact numbers | Booking or moving an appointment |
| Doctor in ClinicTek | The draft of a visit opened before the connection dropped | Today's schedule and the waiting queue | Approving the visit, invoices, payments |
| Cashier | Recording an order with a stable ID so sync cannot duplicate it | Menu items and prices | Card payments and anything that depends on live stock |
Every row follows one rule. If a delay can harm another person or cost money, the action needs the server. If only the person doing it is affected, it can wait on the device.
How we drew the line in ClinicTek, and what Herafy GEE does offline
In ClinicTek, the day's schedule and the waiting queue stay readable as last loaded when the internet drops. ClinicTek keeps the draft of a visit the doctor opened before the connection dropped and sends it once the device is back online. Booking, visit approval, invoices and payments need a connection. We drew the line there because an offline booking could give the same slot to two patients, and financial records need one correct copy. If the visit changed at the clinic while the doctor's phone was offline, ClinicTek keeps both versions and asks the doctor to choose.
The craftsperson's phone app we built for Herafy GEE is offline-first. It keeps working when the signal drops at a job site and syncs when the connection returns.
Cache each resource on purpose
Pick a caching strategy per resource type. Stale-while-revalidate serves the saved copy if there is one and fetches a fresh copy from the network at the same time to update it. Network-first tries the network and falls back to the saved copy if the request fails. Network-only caches nothing. ClinicTek's service worker splits resources like this:
| Resource | Strategy | Why |
|---|---|---|
| Static interface files: scripts, styles and brand images | Stale-while-revalidate, in a versioned cache | The interface opens without waiting for the network, and the newest copy arrives in the background |
| The patient portal's latest data and queue | Network-first with cache fallback, keeping the last 40 responses | Patients still see their last data when the connection drops |
| Signed-in staff pages | Network-only | No page with patient data sits in the service worker's cache |
| Create, update and delete requests | Network-only; the service worker never caches them | Offline writes go through the command queue |
| Booking, payment, invoices, files and account pages | Network-only | They need a live check on the server |
| Any other page that fails to open offline | A static page that explains the outage; visit, invoice and payment pages are left to the browser | Never an old copy of a signed-in page |
Clean old caches only after the new version is ready; ClinicTek deletes them when the new service worker activates. Test a partial deployment, a failed asset request and a tab that stays open across an update. A successful install event does not prove every required file arrived.
Keep records in IndexedDB, with expiry and eviction in mind
Use IndexedDB, or a reliable layer over it, for structured records. web.dev advises against localStorage for complex data because its API is synchronous, and a service worker cannot reach it. Give every record a schema version, an expiry date and a deletion rule.
Treat the local copy as temporary. By default browsers store site data as "best-effort": under storage pressure they delete an origin's data all at once, starting with the least recently used sites. With tracking prevention on, Safari deletes script-created data for any site the user has not interacted with in the last seven days of browser use. You can request persistent storage with navigator.storage.persist(), and users can still clear it.
ClinicTek stamps every local record with a schema version and a key that ties it to one clinic and one user, and drafts and snapshots carry an expiry. It clears local data on sign-out and on an account switch, and a session for another clinic cannot read it. Retention depends on the data:
| Data on the device | Maximum retention |
|---|---|
| Cached data for staff's current work screens, such as the schedule and queue | 7 days |
| Visit drafts | Until synced or discarded, 30 days at most |
| Commands waiting in the sync queue | Until they reach the server, the user resolves them, or the account's data is cleared |
| The patient portal's latest data | 24 hours |
| The patient portal's queue | 15 minutes |
| Platform-admin data, and booking or payment submissions | Never stored or queued on the device |
ClinicTek deletes expired cached data and drafts, and any record with an outdated schema, when it next reads them. If a draft cannot be saved, the user sees one message they can act on: "This draft could not be saved on this device. Keep this page open and try again."
Record commands instead of replaying network requests
Persist a semantic operation such as "complete checklist" or "add note" with a unique ID, payload version, creation time, tenant, actor and dependencies. A raw URL and body are brittle when the API evolves. Move each operation through pending, sending, synced, failed, or needs-attention states. The server must handle the ID idempotently, so the same command arriving twice produces one result. Keep a visible local history so the user can tell saved-on-device from accepted-by-server.
ClinicTek's sync endpoint accepts named operations and never URLs, and today it allows exactly one: updating a visit draft. Each command carries a unique ID, the device ID and the version of the record it was based on. The server stores the first outcome for every command, together with a hash of its content, and rejects the same ID with different content. If the response is lost after a command is sent, later edits go into a new command and the first one stays untouched, so replaying it is always safe.
We add another operation only after it has validation, permission checks, safe replay, conflict detection and an audit trail. It also needs a conflict screen in both languages and allow-and-deny tests for every role.
Sync on triggers you control
Run sync when the app opens, when the browser reports a connection, when the user returns to the app and when they ask for it. Use Background Sync as an extra where the browser supports it. MDN marks it as limited availability because it does not work in some of the most widely used browsers.
Retry network errors, server errors and 429 (too many requests) responses with exponential backoff plus a little random jitter, so devices do not all retry at the same moment. Stop retrying when validation rejects a command, and move it to needs-attention, as ClinicTek does. In ClinicTek a conflict pauses only the affected record while other records keep syncing. Show the age of the oldest pending command; it is the clearest sign that sync has stalled.
Show conflicts to the user
Send the record version with every update. If the server copy changed, the server rejects the command and returns enough context to explain the conflict. ClinicTek then keeps both copies and opens a sheet titled Review this saved draft. It shows Your saved draft next to Current clinic version and offers two buttons, Keep my draft and Use clinic version. Neither copy is discarded automatically.
Let the latest edit overwrite the other only when losing the earlier edit is acceptable for that data and the app tells the user.
For conflict policy by data type, including when a merge is enough and when a person must decide, read our guide to offline sync conflict resolution.
Secure shared and lost devices
Store only what the task needs, avoid long-lived secrets and tie local access to the signed-in session. Clear or lock local data on sign-out, on a role change, and on device revocation when the device next connects. A device that never reconnects cannot receive a remote wipe. Stop one account from reading another account's cached data. Once changes sync, protect them with server backups; the local store is never a backup.
When the server rejects a session or permissions, ClinicTek deletes that account's data on the device, including drafts not yet sent, and tells the user: "Your sign-in expired. Saved device data was cleared to protect patient privacy."
Upgrade the service worker and the local schema together
A new service worker installs in the background and waits until no open page uses the old one, unless your code forces activation. Meanwhile a new interface may expect a new local schema while an old tab still runs. Coordinate worker activation, the IndexedDB migration, command payload versions and API compatibility. Never delete the queue during an upgrade, make migrations resumable, and move any command that cannot be converted to the new format into needs-attention.
ClinicTek holds a waiting update while a staff session is open. The status bar says an update is ready, and staff apply it once they have finished entering their current changes. The patient portal, which holds no drafts, applies the update and reloads on its own. A service-worker update keeps pending drafts.
Show network state honestly
navigator.onLine is a hint. A device on a local network with no internet access can still report itself online, and MDN calls the property inherently unreliable. Judge connectivity from real request outcomes, and tell apart a lost connection, a failing server, an expired session and a third-party outage.
ClinicTek bases its status bar on a real reachability check and shows states such as these:
- Offline: "No internet connection. Safe drafts stay on this device." It stays visible.
- Syncing: "Reconnecting and syncing…" during recovery.
- Up to date: shown briefly, then hidden.
- Needs attention: stays until the user reviews the affected item, with a Review saved work button.
- Waiting to retry: "Work is saved on this device. We will retry automatically.", with a Retry sync button.
Test two devices on one record
Airplane mode on one phone will not show you what this test shows:
- Open the same record on two devices, then take both offline.
- Make a different edit on each.
- Reconnect the first device, then the second. Repeat in the opposite order.
- Check that both commands arrive with stable IDs, that the second user sees the conflict and that no side effect happens twice.
- Add a deletion on one device, a permission change during the outage and a full storage quota.
Then copy this lifecycle checklist into your test plan:
- Slow and flapping networks, and duplicate responses
- The browser closed mid-write to IndexedDB
- A full storage quota, and the browser evicting site data
- A device clock that differs from the server
- A session that expires with commands still queued
- A service-worker update with an old tab open
- An API release while old commands sit in the queue
- Keyboard and screen-reader use in recovery dialogs
- Every browser and mobile OS you support, since background policies differ
Roll out one workflow at a time
Pick one high-value workflow and pilot it on your users' real devices and networks:
- Write its boundary with the role table above, and the failure cases you expect.
- Train users on what each connection state means and on the manual fallback.
- Track the oldest pending command, command counts, failure reasons, conflict rate and the app version, without copying record content into your logs.
- Keep a rollback path that preserves records already synced. ClinicTek can stop new offline drafts with one switch while existing drafts stay visible and exportable.
- Extend the boundary to a second workflow once these numbers settle.
We build installable web apps as part of website and web app development. Before we write any code, we agree with you on which work continues offline. If your app also runs on phones, our Flutter and Laravel architecture guide shows how one API serves the same command queue from a mobile client. The field service guide shows a bounded offline workflow for technicians. Send us your project brief to review your offline boundary with us.




