Home / PWA and Offline / Expense Tracker PWA

Expense Tracker PWA in JavaScript, Free with Live Demo

Free expense tracker PWA in plain JavaScript. Log spending, see a donut chart and a 7 day bar chart, set a budget and sync offline entries with Background Sync.

Open live demoDownload HTML fileView code on GitHub
Expense Tracker PWA JavaScript project: a spending tracker with charts that syncs when back online

Runs on: Background Sync. App and charts: every modern browser. Background Sync: Chrome, Edge and Samsung Internet. Other browsers sync when the page is open and online.

What is the Expense Tracker PWA?

Log what you spend by category and see where the money goes, with a donut chart by category, a bar chart for the last seven days and a monthly budget bar. You can export everything to CSV.

Entries are saved in IndexedDB first. If you are offline, they are marked as waiting, and the Background Sync API wakes the service worker to send them once you are online, even if the tab is closed.

Good for

  • Personal budgeting
  • Apps used on poor mobile networks
  • Learning Background Sync
  • Canvas charts without a library

What this project does

How it works

  1. Save locally firstEvery expense goes into IndexedDB right away, marked as not yet synced.
  2. Ask for a syncThe page registers a sync tag. The browser wakes the service worker when it is online, even if the tab is closed.
  3. Flush the outboxThe worker sends waiting entries to the server (simulated here) and tells the page, which marks them synced.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

// Page: save locally, then ask the browser to sync when online
await db.put("expenses", { ...expense, synced: false });
const reg = await navigator.serviceWorker.ready;
await reg.sync.register("sync-expenses");

// sw.js: runs when the connection is back, even if the tab is closed
self.addEventListener("sync", (event) => {
  if (event.tag === "sync-expenses") event.waitUntil(sendUnsynced());
});

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

What is the Background Sync API?

It lets a web app ask the browser to run a task when the connection comes back. The service worker gets a sync event and can send saved data.

Which browsers support Background Sync?

Chrome, Edge and Samsung Internet. In other browsers this app syncs when the page is open and online.

Are the charts made with a library?

No. Both charts are drawn with the Canvas 2D API in about 20 lines each.

More PWA and Offline projects