Why a Single-File PWA
A Progressive Web App (PWA) is a website that behaves like an installed app. You open it once in the browser, tap "Add to Home Screen", and from then on it opens full screen with its own icon, even without an internet connection.
For small, focused tools (a checklist, a stock register, a daily report form), I keep the whole app in one HTML file. All the markup, styles and JavaScript live in index.html, plus two small helper files. The payoff:
- No build step. There's no npm, no bundler and nothing to compile. Edit the file, push, done.
- No backend. Data stays in the browser's storage on the device.
- Free hosting. GitHub Pages serves static files at no cost, with HTTPS included.
- Easy updates from a phone. You can edit and commit through the GitHub website if you're away from the PC.
What You Need
- A free GitHub account
- A text editor (VS Code on a PC, or the GitHub web editor)
- Two icons: a 192×192 and a 512×512 PNG
- Optional: your own domain name
Step 1 — The File Layout
The whole project is four files plus icons:
my-app/
├── index.html ← the entire app
├── manifest.webmanifest ← name, icons, colours
├── sw.js ← service worker (offline support)
├── icon-192.png
└── icon-512.png
Step 2 — The App Itself (index.html)
Here is a stripped-down but complete example: a tiny "stock count" tool that adds items and remembers them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Stock Count</title>
<link rel="manifest" href="manifest.webmanifest">
<meta name="theme-color" content="#12181a">
<link rel="apple-touch-icon" href="icon-192.png">
<style>
body{font-family:system-ui,sans-serif;max-width:480px;margin:auto;padding:16px}
input,button{font-size:16px;padding:10px}
li{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #ddd}
</style>
</head>
<body>
<h1>Stock Count</h1>
<form id="f">
<input id="name" placeholder="Item" required>
<input id="qty" type="number" placeholder="Qty" required>
<button>Add</button>
</form>
<ul id="list"></ul>
<script>
const KEY = "stock-count-v1";
let items = [];
try { items = JSON.parse(localStorage.getItem(KEY)) || []; } catch (e) {}
function save() {
try { localStorage.setItem(KEY, JSON.stringify(items)); } catch (e) {}
}
function draw() {
const list = document.getElementById("list");
list.innerHTML = "";
items.forEach(it => {
const li = document.createElement("li");
li.textContent = it.name; // textContent, never innerHTML, for user input
const b = document.createElement("b");
b.textContent = it.qty;
li.appendChild(b);
list.appendChild(li);
});
}
document.getElementById("f").addEventListener("submit", e => {
e.preventDefault();
const nameEl = document.getElementById("name");
const qtyEl = document.getElementById("qty");
items.push({ name: nameEl.value.trim(), qty: +qtyEl.value });
save(); draw(); e.target.reset();
});
draw();
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js");
}
</script>
</body>
</html>
stock-count-v1). If you ever change the data format, bump it to v2 and write a small migration, instead of breaking the data people already have on their phones.Step 3 — The Manifest
The manifest tells the phone what to call the app, which icon to use and how to open it. Save this as manifest.webmanifest:
{
"name": "Stock Count",
"short_name": "Stock",
"start_url": "./",
"scope": "./",
"display": "standalone",
"background_color": "#12181a",
"theme_color": "#12181a",
"icons": [
{ "src": "icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" }
]
}
Use relative paths (./) everywhere. GitHub Pages often serves a project from a sub-folder like username.github.io/my-app/, and absolute paths starting with / would point to the wrong place.
Step 4 — The Service Worker (Offline Support)
The service worker is a small script the browser keeps running in the background. Mine uses network-first, cache as fallback: when online you always get the newest version, and when offline you get the last saved copy.
const CACHE = "stock-v1";
const FILES = ["./", "./index.html", "./manifest.webmanifest", "./icon-192.png", "./icon-512.png"];
self.addEventListener("install", e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)));
self.skipWaiting();
});
self.addEventListener("activate", e => {
e.waitUntil(
caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))))
);
self.clients.claim();
});
self.addEventListener("fetch", e => {
if (e.request.method !== "GET") return;
e.respondWith(
fetch(e.request)
.then(res => {
const copy = res.clone();
caches.open(CACHE).then(c => c.put(e.request, copy));
return res;
})
.catch(() => caches.match(e.request).then(r => r || caches.match("./index.html")))
);
});
stock-v1 → stock-v2). That's the cleanest way to make sure old cached files get cleared on everyone's phone.Step 5 — Publish on GitHub Pages
- On GitHub, create a new repository (for example
my-app). On the free plan, Pages needs the repository to be public. - Upload the files: Add file → Upload files, drag them in, then Commit changes.
- Open Settings → Pages.
- Under Build and deployment, set Source to Deploy from a branch, Branch to
main, folder/ (root), and click Save. - Wait a minute or two. The page shows your address, for example
https://username.github.io/my-app/.
Step 6 — Install It on a Phone
- Android (Chrome): open the link, tap the ⋮ menu → Add to Home screen (or the "Install app" prompt).
- iPhone (Safari): open the link, tap Share → Add to Home Screen.
Now turn on flight mode and open it from the home screen. If it loads, your offline support works.
Optional — Use Your Own Domain
- In the repository, go to Settings → Pages → Custom domain, enter
app.yourdomain.comand save. GitHub adds aCNAMEfile to the repository. - At your DNS provider, add a CNAME record: name
app, targetusername.github.io. - After it starts working, tick Enforce HTTPS on the same Pages screen.
If your DNS is on Cloudflare, set that record to DNS only (grey cloud) so GitHub can issue its HTTPS certificate. I cover that in Moving Your Domain's DNS to Cloudflare Without Breaking Email.
The Limits — Be Honest About Them
| Limit | What it means | Workaround |
|---|---|---|
| Data lives on one device | Your phone and PC don't share records | Add a Backup (download JSON) and Restore button, or move to a small cloud database later |
| Clearing browser data wipes it | Users can lose records | Remind users to back up; show "last backup" date in the app |
| Public repository | Anyone can read the code | Never put passwords or API keys in the file |
| iPhone storage can be cleared | Safari may remove data of apps not opened for weeks | Install to home screen, and back up regularly |
Common Issues
"Add to Home screen" doesn't appear on Android. Check that the manifest link is in the <head>, both icons load, and the site is on HTTPS. Chrome DevTools → Application → Manifest lists exactly what's missing.
Changes don't show up after pushing. The old version is cached. Bump the cache name in sw.js, push again, then close and reopen the app twice.
404 on GitHub Pages. Make sure the file is named exactly index.html (lower case) and sits in the folder you chose as the Pages source.