← All guides PWA · WEB APPS

Deploying a Free Single-File PWA on GitHub Pages

An installable app that works offline, keeps its data on the device and costs nothing to host. This is the same pattern behind the site safety app I use every day at work.

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:

What You Need

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>
Version your storage key (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")))
  );
});
Every time you release an update, change the cache name (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

  1. On GitHub, create a new repository (for example my-app). On the free plan, Pages needs the repository to be public.
  2. Upload the files: Add file → Upload files, drag them in, then Commit changes.
  3. Open Settings → Pages.
  4. Under Build and deployment, set Source to Deploy from a branch, Branch to main, folder / (root), and click Save.
  5. 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

Now turn on flight mode and open it from the home screen. If it loads, your offline support works.

Optional — Use Your Own Domain

  1. In the repository, go to Settings → Pages → Custom domain, enter app.yourdomain.com and save. GitHub adds a CNAME file to the repository.
  2. At your DNS provider, add a CNAME record: name app, target username.github.io.
  3. 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

LimitWhat it meansWorkaround
Data lives on one deviceYour phone and PC don't share recordsAdd a Backup (download JSON) and Restore button, or move to a small cloud database later
Clearing browser data wipes itUsers can lose recordsRemind users to back up; show "last backup" date in the app
Public repositoryAnyone can read the codeNever put passwords or API keys in the file
iPhone storage can be clearedSafari may remove data of apps not opened for weeksInstall 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.

← Back to all guides