Most "app or web?" arguments end with one of them being treated as the lesser copy. In practice the interesting version is both: the screens live inside a native shell, the content keeps living on the web, and the two have to agree on a small set of things — back navigation, session, deep links, and what happens when someone taps a link that is not ours. Everything else can stay separate.
This is the contract I keep coming back to after shipping a marketplace app (iOS + Android) on top of a web app that already worked in a browser. It is not framework-specific, and it does not require rewriting the front end as native screens — which is usually what kills the plan before it starts.
Decide what the shell owns, once
The failure mode is a grey zone where both sides think they own the same thing. Writing the list down before coding saves the argument later:
- The shell owns: the tab bar, the gesture for going back, the status bar and safe areas, the splash screen, push permission, the app icon and version.
- The web owns: every screen inside a tab, the session, form state, scroll position, routing between pages, and any content that changes weekly.
- Both share: a way to ask the other to do something, and a way to say it was done.
That third item is where the bugs would be if it were left implicit, so I make it an actual message protocol.
Keep one message contract, not five
The web page sends messages up to the shell through one injected object; the shell sends messages down through the same channel. Naming them like events with a small payload keeps it readable six months later.
function toNative(type, payload) { // web -> native
window.__NATIVE__?.post?.(JSON.stringify({ type, payload }));
}
window.__NATIVE_EVENT__ = function (raw) { // native -> web
const { type, payload } = JSON.parse(raw);
if (type === "back") {
// the gesture arrived; the web decides what "back" means here
if (history.state?.tabRoot) return toNative("exitTab");
history.back();
}
if (type === "session") {
// the shell refreshed the token; keep the web session in step
sessionStorage.setItem("session", payload.token);
}
};
Two messages carry most of the traffic: back (the shell says the gesture happened, the web answers whether it moved) and open (the web asks the shell to open something outside the app in the system browser).
The rule that matters: the web answers, the shell does not assume. A hardware back that always closes the current tab will close a half-filled checkout the moment someone taps back once, and no amount of native polish fixes that afterwards.
Tabs that stay alive, and the memory bill
Keeping each tab's web view alive is what makes the app feel native: you come back to the feed and it is exactly where you left it, scroll position included. The cost is memory, so the tabs that stay resident are the ones people return to many times a day, and tabs opened from a deep link are created on demand.
Two details separate "keeps state" from "keeps stale state":
-
Scroll restore comes from the web. Each tab reports its offset on a throttled scroll event and the page restores it on
pageshow. A shell-level restore guesses wrong as soon as a page changes height. - Every tab is re-checked on resume. When the app returns from the background, the current tab fetches only its own light endpoint — counts, badges, a version number — instead of reloading. Reloading loses the form; not reloading shows a count that is a day old.
External links are a routing decision
Any link that is not ours — a maker's store page, a payment window, a mail client — should leave the app. Detecting that in the web layer is much easier than in the shell: the web knows its own router, so it can send open with the URL for the shell to hand to the system browser. Letting the web view navigate to a third-party site instead leaves a person on a page with no address bar and no way back.
The same rule covers target="_blank", window.open, and anchors a CMS injects into article bodies. One delegated click listener on document and one check against the router usually does it.
The session belongs to one side
If the app has its own login and the web has its own login, there are two of everything: two expiry rules, two logout buttons, two ways to lose a refresh token. Pick the web as the owner of the session cookie and let the shell hold only a refresh token, handed down as a session message. Then logout is a single call, and the "signed in on the web but not in the app" state never exists.
On iOS this also settles the cookie question early, because the web view's data store has to persist for the session to survive a relaunch. That is a one-line decision at setup and a week of debugging if it is discovered late.
Treat the static content as part of the contract
When content is published through a web admin, the app does not need a store release for every new listing — but it does need to stop serving yesterday's assets. Versioning the bundle (?v= on one script and one stylesheet, bumped on each deploy) plus a short cache on the HTML makes a deploy feel instant inside the app without turning every open into a full download. The same version number goes into the tab's light endpoint, which is how the app notices a deploy that happened while it was in the background and quietly updates its badges.
What I would tell someone starting this today
- Write the message contract first, in one file, with events named after what the user did rather than what the code does.
- Let the web own navigation state. The shell asks; it does not decide.
- Keep the resident tabs small in number and honest about their scroll position.
- Send every outbound link to the system browser and never let a web view become a dead end.
- One session owner, one logout.
- Version the assets, and give the app one cheap endpoint to notice a deploy.
The screens being written once is the part people argue about. What decides whether the result feels like an app is much smaller in my experience: a handful of messages, one owner per piece of state, and a rule that the back gesture is answered rather than overridden.
I run a small studio in Seoul that builds this kind of thing — web app, native shell, store submission — usually in a week or two rather than a quarter. If you are weighing an app against a web app, or already have one and need the other: cpcai-studio.web.app/en · yyhak12345@gmail.com
Top comments (0)