◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
Articles/Dev Tools
⟐ Dev Tools/2026-06-28Advanced

Gemini API × PWA Complete Implementation Guide — Service Workers, Offline AI, and Web Push Notifications for App Store-Quality Web Apps

Build production-grade AI web apps by combining Gemini API with Progressive Web App techniques — Service Worker caching, IndexedDB for AI context persistence, offline fallbacks, and Web Push notifications — plus instrumentation to surface API cost from your cache hit rate.

gemini-api291PWAService WorkerofflineWeb PushIndexedDBJavaScript

✦ Premium Article

The feedback came in the morning after I let my first users try a Gemini-powered web app: "It went completely blank when my train went through a tunnel." For an AI-centric application, becoming completely unusable the moment connectivity drops is not just a bug — it's a product-ending experience.

That frustration pushed me to seriously explore the combination of Gemini API and Progressive Web Apps. PWAs give you a Service Worker — a JavaScript proxy that sits between your app and the network. With the right caching strategies, offline fallbacks, and background sync, you can build AI apps that keep working in a tunnel, on a plane, or anywhere else connectivity is unreliable.

This guide covers the full picture: caching Gemini API responses intelligently, persisting AI conversation context in IndexedDB, queuing offline requests with Background Sync, and triggering personalized Web Push notifications using Gemini as the decision engine. These aren't toy examples — everything here is production-tested code.

Why PWA + Gemini API Is Worth the Investment

You have options for distributing an AI-powered mobile experience: React Native, Flutter, Capacitor. PWA has a different set of trade-offs that make it particularly attractive for AI applications.

The most underrated advantage is deployment speed. When Gemini releases a new model or you want to update a prompt strategy, a PWA update is live the second you deploy. No App Store review, no waiting for users to update. Given how quickly the Gemini API ecosystem evolves, being able to iterate in minutes rather than days matters.

The second advantage is installability without friction. Users tap "Add to Home Screen" and your app launches with a splash screen, runs full-screen, and feels native — with zero App Store friction. For AI productivity tools, this dramatically reduces the barrier between a first visit and daily use.

The third advantage is what this article is actually about: the offline experience. Most AI web apps treat connectivity as a hard requirement. Service Workers turn that assumption on its head.

Project Structure and Service Worker Registration

The following examples use Vite + TypeScript, but the concepts apply equally to Next.js, SvelteKit, or any modern build setup.

my-gemini-pwa/
├── public/
│   ├── manifest.json        # PWA manifest
│   ├── sw.js               # Service Worker (built and placed here)
│   ├── offline.html        # Offline fallback page
│   └── icons/
├── src/
│   ├── main.ts
│   ├── gemini.ts           # Gemini API client
│   ├── sw-registration.ts  # Service Worker registration
│   └── db.ts               # IndexedDB management
└── vite.config.ts

Register the Service Worker after the page has loaded, and handle the update flow so users see a notification when a new version is available:

// src/sw-registration.ts
export async function registerServiceWorker(): Promise<void> {
  if (!('serviceWorker' in navigator)) {
    console.warn('Service Workers not supported in this browser');
    return;
  }
 
  try {
    const registration = await navigator.serviceWorker.register('/sw.js', {
      scope: '/',
      // Prevent the browser from caching the SW file itself
      updateViaCache: 'none',
    });
 
    registration.addEventListener('updatefound', () => {
      const newWorker = registration.installing;
      if (!newWorker) return;
 
      newWorker.addEventListener('statechange', () => {
        if (
          newWorker.state === 'installed' &&
          navigator.serviceWorker.controller
        ) {
          showUpdateBanner();
        }
      });
    });
 
    console.log('✅ Service Worker registered:', registration.scope);
  } catch (error) {
    console.error('Service Worker registration failed:', error);
  }
}
 
function showUpdateBanner(): void {
  const banner = document.createElement('div');
  banner.innerHTML = `
    <div style="position:fixed;bottom:16px;left:16px;right:16px;background:#1a73e8;
      color:white;padding:12px 16px;border-radius:8px;display:flex;
      justify-content:space-between;align-items:center;z-index:9999;">
      <span>A new version is available</span>
      <button onclick="window.location.reload()"
        style="background:white;color:#1a73e8;border:none;
        padding:6px 12px;border-radius:4px;cursor:pointer;font-weight:600;">
        Reload
      </button>
    </div>
  `;
  document.body.appendChild(banner);
}

The updateViaCache: 'none' setting is easy to miss but important. Without it, the browser may aggressively cache the Service Worker file itself, delaying update delivery to users.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Instrument Service Worker hits/misses to see exactly how many Gemini API calls you avoid
✦Hit-rate and cost-saving benchmarks for three caching strategies (exact / normalized / semantic)
✦The order to layer offline support, IndexedDB persistence, and Background Sync at production quality
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Dev Tools2026-10-29
Before You Install gemini-api: It Is Not Gemini CLI, and Where I Decided It Belongs
The Gemini API CLI (gemini-api, beta) that appeared on 10/27 is not a successor to Gemini CLI. Here is where I placed it after reading the README, what to check with --dry-run before any billing, and how to pin it in CI.
⟐ Dev Tools2026-08-21
Why My Length Limit Only Failed on the English Notifications, and the Width-Based Fit That Replaced It
I had Gemini write push notifications in Japanese and English, and only the English ones came out truncated on real devices. The culprit was measuring length in characters. Here are the measured widths and the post-generation fitting code that fixed it.
⟐ Dev Tools2026-08-10
Finding the questions your help docs never answer, by asking Gemini to write the quiz
When support keeps asking something your help page already covers, generate questions from that page and check whether the page alone can answer them. A two-pass audit pipeline with call design and cost math.