Repository navigation
Offline
form.md opens without a connection to the server.
- Pages. A service worker keeps the built client and a copy of the signed-in app shell, and page bodies live in the browser's IndexedDB as the same CRDT documents the server holds, so pages saved on the device open, show their text and accept typing while the server is unreachable, including after the browser was closed and reopened offline (the device remembers whether you may edit each page). Text edits merge into the server's copy when the connection comes back.
- Databases. Databases opened or kept on the device open with up to 1000 rows in every view, the row pages among them open with their properties and body, and rows added, edited or deleted offline are queued in the browser and sent when the server is back.
- What still needs the server. Everything else (schema and view changes, ad-hoc filters and further rows, search, comments, the inbox, uploads, AI and settings) needs the server.
| Path | What lives there |
|---|---|
web/public/sw.js |
The service worker: asset cache, shell cache, offline navigation, push notifications |
web/public/manifest.webmanifest |
The web app manifest that makes form.md installable |
web/src/ui/pull.ts |
Pull to refresh in the installed app on touch devices |
web/src/ui/offline.ts |
Registers the worker, asks it to refresh the shell and cache assets, the "Available offline" action |
web/src/ui/offline-list.ts |
The per-account list of pages kept for offline use (in localStorage) |
web/src/engine/doc/docs.ts |
Document sessions persisted to IndexedDB (y-indexeddb); clearLocal on sign-out |
web/src/ui/status.ts |
The connection notice |
internal/static/offline.go |
GET /offline.json: the list of built assets |
internal/server/server.go |
/offline-shell: the signed-in app document without a page |
- About 2.5 seconds after the app starts, it registers
/sw.jswith scope/(in browsers that support service workers). When it activates it claims the open pages, so the page that registered it is served by it from then on without a reload. - On install, the worker fetches
/offline.jsonand caches thecoreassets (those the app document references or preloads) in the cacheformmd-assets. - About 20 seconds after start, when the browser is idle and not in data-saver mode, it caches every asset listed in
/offline.jsonand drops cached assets the current build no longer lists. - While online and signed in, the app asks the worker to fetch
/offline-shelland keep it in the cacheformmd-shell. The shell is the app document the server renders for you, with your account, the current workspace's page tree, tags, teamspaces and favorites. The app refreshes it after start and again 4 seconds after the page tree changes. - Files and pictures under
/files/<id>that this browser has loaded whole are kept in the cacheformmd-filesand answered from it when the network fails. - Requests under
/assets/are answered from the cache first. Navigations to/,/p/<id>,/library,/trashand/inboxgo to the network first; when the network fails, the worker answers with the cached shell, marked with the right route so the layout does not move on first paint.
-
What you open is kept. Every page you open is kept in IndexedDB on that device, and every database you open while the service worker controls the tab is kept in the worker's API cache (
formmd-api: the readsGET /api/pages/<id>,GET /api/collections/<id>andGET /api/rows/<id>). - Keeping pages you have not opened. To keep pages you have not opened, use the page menu item Available offline (shown for document and database pages you can view, not for database rows, in browsers with service workers).
- What Available offline keeps. It keeps that page and all of its subpages synced into IndexedDB, the first view of each database among them in the API cache together with the row pages in its first window (their details and bodies), and the pictures and files those pages show in the file cache, now, shows how many were saved, and re-syncs them about 30 seconds after each start while online.
- Turning it off. Choosing it again stops keeping them.
A kept database keeps up to 1000 rows: the worker caches GET /api/collections/<id>?view=<view>&rows=1000 for every table and list view, answers an offline read of that database from that copy first, and the row pages of the first 1000 rows are synced. Without any marking, the 20 pages and databases this account opened most recently (on any device, from GET /api/recent) are kept the same way at each start. The command Keep recent pages offline (offline.recent) turns that off or on again for this browser.
Other views ask the server with POST /api/collections/<id>/query, /chart or /feed, which the browser cache cannot hold as such.
-
Exact answers. The worker keeps each successful first-page answer (no search text, offset 0) under a key made from the collection path and a SHA-256 of the request body, and answers the same request from it only when the network fails.
-
A fallback per view. A canonical
/queryanswer (no group or lane paging, tree, ad-hoc filter, row ids, sort override or date range) is also kept under a key for its view, and any plain request for that view (one without group or lane paging, tree, ad-hoc filter or row ids) falls back to it when its exact request was never made (another calendar month, say); -
Charts and feeds never borrow.
/chartand/feedanswers are only ever served for the exact request, so a dashboard widget never gets another widget's numbers and clicking a chart mark offline never shows the chart's totals as its rows. -
Who fetches. The keeper asks the worker to fetch these itself (the
offline-querymessage, like the row and page reads), so it works even before the worker controls the page, and the worker claims open pages when it activates. -
Which views. For kept and recent databases at the keeper's pass, and for any database opened while online (about two seconds after opening, once per session, unless Keep recent pages offline is off), it keeps the database and asks once for every board, gallery, calendar, timeline, map, graph, chart and feed view and every dashboard widget (with its sparkline).
-
Heatmaps. A heatmap's request depends on the day and is kept when the heatmap is opened online.
-
The map. The map's land outline (
/maps/world-110m.json) is in/offline.jsonand cached with the built assets.
Queued database changes are sent when the browser comes back online, when the app's live connection to the server is re-established (a server restart or a dropped link, where the browser itself never went offline), and at start.
A row added offline gets an id made in the browser, in the same form as server ids. POST /api/collections/<id>/rows accepts that id: sending the same id again to the same database returns the row already made, so a replay that had already arrived does no harm, and an id any other page uses answers 409 id_taken.
| Works offline | Needs the server |
|---|---|
Opening the app at /, a page, the library, the trash or the inbox route |
Moving rows, schema changes, filters, searches, more rows and forms |
| Adding rows, editing cells and row titles, and deleting rows, in kept or opened databases: kept in this browser and sent when the connection is back (creates, then edits, then deletes; last write wins) | |
| Table and list views of kept or opened databases, with up to 1000 rows (the first window for a database only opened) | Views of databases that are neither kept, recent nor opened online in this browser; a database opened in the first seconds of the very first visit, before the worker is running, until the keeper's pass |
| Board, gallery, calendar, timeline, map, graph, chart, dashboard and feed views of kept, recent or opened databases, as of the keeper's last pass; heatmaps as last opened online | Picking the rows behind a chart mark, and loading more feed entries |
| The sidebar (page tree, favorites, tags) of the workspace that was current at the last shell refresh | Search and the command palette's answers; the trees of other workspaces |
| Reading pages saved on this device | Comments, the inbox contents, sharing, history |
| Typing in those pages; edits are kept in IndexedDB and sync when the server is back | Uploads, and files or pictures that are neither on a kept page nor loaded before |
| Files and pictures on kept pages, and any this browser has loaded before | |
| Row pages of kept or opened databases (in the first window), and row pages opened before | |
AI, agents, settings and anything else under /api
|
A page that was neither opened nor kept on this device shows its title from the tree but no body; a database row page or a page of another workspace that was neither opened nor kept shows nothing, since its title is not in the cached tree. While the server is unreachable the app shows: "Cannot reach the server. Pages saved on this device stay open, and edits to their text sync when it is back." with a Retry button, and "Connection restored." when it is back.
/manifest.webmanifest (linked from the app document) names the app form.md, starts it at / and opens it in its own window ("display": "standalone") with the form.md icon. Browsers that support installing web apps offer to install it; the installed app uses the same service worker and the same offline behaviour as a tab.
In the installed window, a Sync now button appears in the top bar. It reconnects the live connections, checks the server, and reloads the page tree of the current workspace when the server answers. On touch devices, pulling down at the top of the page in the installed window does the same. In a browser tab the button is hidden; the same action is registered as the command "Sync now".
-
What is deleted. Signing out deletes the cached shell, the API cache, the file cache and every IndexedDB document database the app created (names starting
formmd-doc-), so the next person on that browser starts clean. -
Changes not yet sent. Database changes still queued are kept in
localStorageunder the account's id, so they are never sent under anyone else's session and are sent when that account signs in again on this browser. - Another account on the same browser. When a different account starts the app than the one that last used it, the app deletes the same caches and databases before it loads.
- A session that ended. When the server answers that the session has ended (expired or revoked), the app deletes the shell, API and file caches before it goes to the sign-in page.
- What is kept. The asset cache holds only the public client build and is kept.
- Browsers only run service workers in a secure context: a page served over HTTPS, or from
http://localhostorhttp://127.0.0.1. An instance reached over plain HTTP by any other name gets no offline start; see TLS-and-ACME. (This is a browser rule, not a form.md setting.) - Nothing to configure on the server:
/sw.js,/manifest.webmanifest,/offline.jsonand/offline-shellare served by the binary./sw.jsgets its own Content-Security-Policy (default-src 'none'; connect-src 'self'). - Kept pages are plain copies in each browser's storage and are not covered by Encryption. Signing out removes them.
- After an upgrade, the new build's
/offline.jsonlists new asset names; the worker caches them and prunes the old ones on the next idle pass.
- A new top-level app route that should open offline is added to
APP_ROUTESinweb/public/sw.jsand handled for/offline-shellininternal/server/server.go. - The worker caches only same-origin requests:
GETassets, the shell, the page, database and row reads matched byAPI_READSand whole (non-range)200file responses, and thePOSTview reads matched byQUERY_READS. Messages from the page that ask it to fetch something are checked against the same patterns and the worker's own origin. API and file reads go to the network first, so a cached copy is only ever shown when the server cannot be reached. A new cached read is added to the matching pattern inweb/public/sw.jsand to the cache namesclearLocaland the session guard inweb/src/main.tsdelete. - Anything the app stores per account on the device is removed by
clearLocalon sign-out.
form.md
Running an instance
Using it
- Data-views
- Offline
- API-and-agents
- Form-family
- Context-and-knowledge
- Terminal-and-Claude-Code
- Extensions
Changing the code