<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by RYMS on Medium]]></title>
        <description><![CDATA[Stories by RYMS on Medium]]></description>
        <link>https://medium.com/@razmans?source=rss-a71f56d30305------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UN7FWS2VqFdUwlJhjjFi2w.jpeg</url>
            <title>Stories by RYMS on Medium</title>
            <link>https://medium.com/@razmans?source=rss-a71f56d30305------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:53:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@razmans/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an Offline-First, Installable Web App with React, Firebase and Workbox]]></title>
            <link>https://levelup.gitconnected.com/building-an-offline-first-installable-web-app-with-react-firebase-and-workbox-05aae4aab21b?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/05aae4aab21b</guid>
            <category><![CDATA[progressive-web-app]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[offline-first]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Fri, 20 Nov 2026 16:27:04 GMT</pubDate>
            <atom:updated>2026-11-20T16:27:04.197Z</atom:updated>
            <content:encoded><![CDATA[<h4>A walkthrough of the PWA layer of a real project: precached shell, offline data, an install button, and updates that never interrupt your work.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xfZvczW0VqppzIao" /><figcaption>Photo by <a href="https://unsplash.com/@nordwood?utm_source=medium&amp;utm_medium=referral">NordWood Themes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s say you have built a beautiful web app with React. It looks good on your mobile device, but you feel it could work as an app. The one that I have built here for this example, started as a Vite React web app. It eventually became a kanban board and it looks really good on a mobile device, if I have to say so myself.</p><p>A kanban board is the kind of tool people open in awkward places: a lift, a site visit, a train through a tunnel, but if the board shows a white screen the moment the signal drops, people stop trusting it.</p><p>So, now it works offline, but still, I need to open my web browser each time. Is there a way to convert it directly so that it looks and feel like your run of the mill mobile app?</p><p>I will walk through how I built the offline and install layer of my kanban app (React, Redux Toolkit, Vite, Firebase). It is a closed-team tool, so a few choices, such as wiping cached data on sign-out, are stricter than a public app would need. The code is trimmed from the real project, so, NO, these are not codes about building a kanban board, but it is codes for creating a pure offline capable PWA with React.</p><p>What we’ll build:</p><ol><li>An <strong>app shell</strong> that loads with no network (service worker + Workbox precache).</li><li><strong>Offline data</strong>: boards readable offline, edits queued and synced on reconnect (Firestore persistence).</li><li>An honest <strong>connection indicator</strong>, because navigator.onLine lies.</li><li>An <strong>install button</strong> (Chromium) and a hint for iOS, which has no install prompt.</li><li><strong>Updates that never reload the page mid-edit</strong>, plus a manual <em>Refresh app</em> escape hatch.</li><li><strong>Cache hygiene</strong>: big lazy chunks cached on demand, and cached data wiped on sign-out.</li></ol><h3>The shape of the problem</h3><p>Offline support is really three separate problems, and mixing them up is the most common source of confusion:</p><ul><li><strong>Code (HTML, JS, CSS, icons)-</strong> Cached by: a service worker, stored in Cache Storage</li><li><strong>Data (boards, cards, comments)</strong>- Cached by: Firestore’s IndexedDB cache</li><li><strong>Uploads (images, files)</strong>- Not cached: they need a connection</li></ul><p>The service worker knows nothing about your data, and Firestore knows nothing about your code. Keep them apart in your head and each piece stays small.</p><h3>Step 1: The manifest and vite-plugin-pwa</h3><p>We use vite-plugin-pwa with the injectManifest strategy. That means we write our own service worker (src/sw.ts) and the plugin injects the list of files to precache. It is more work than the zero-config generateSW mode, but we need custom routing, so it pays off.</p><pre>// vite.config.ts<br>import { VitePWA } from &quot;vite-plugin-pwa&quot;;<br><br>export default defineConfig({<br>  plugins: [<br>    react(),<br>    VitePWA({<br>      registerType: &quot;prompt&quot;,          // never update behind the user&#39;s back<br>      strategies: &quot;injectManifest&quot;,<br>      srcDir: &quot;src&quot;,<br>      filename: &quot;sw.ts&quot;,<br>      injectRegister: false,           // we register from React (see Step 5)<br>      manifest: {<br>        name: &quot;TFX Kanban&quot;,<br>        short_name: &quot;TFX Kanban&quot;,<br>        start_url: &quot;/&quot;,<br>        scope: &quot;/&quot;,<br>        display: &quot;standalone&quot;, //Opens without looking like its on a browser<br>        theme_color: &quot;#e8e4db&quot;,<br>        background_color: &quot;#e8e4db&quot;,<br>        icons: [<br>          { src: &quot;/icons/icon-192.png&quot;, sizes: &quot;192x192&quot;, type: &quot;image/png&quot; },<br>          { src: &quot;/icons/icon-512.png&quot;, sizes: &quot;512x512&quot;, type: &quot;image/png&quot; },<br>          { src: &quot;/icons/icon-maskable-512.png&quot;, sizes: &quot;512x512&quot;,<br>            type: &quot;image/png&quot;, purpose: &quot;maskable&quot; },<br>        ],<br>      },<br>      injectManifest: {<br>        globPatterns: [&quot;**/*.{js,css,html,png,woff2,webmanifest}&quot;],<br>        // Large, rarely-needed files are NOT precached (see Step 6).<br>        globIgnores: [&quot;**/assets/sketch-editor/**&quot;, &quot;excalidraw/**&quot;],<br>      },<br>    }),<br>  ],<br>});</pre><p>Three details from the code above that you need to look at here:</p><ul><li>display: “standalone” is what makes the installed app open without browser and makes it feel like an app.<br>- <strong>A maskable icon</strong> lets Android crop your icon into whatever shape the launcher uses without cutting off the logo.<br>- registerType: “prompt” is a product decision, not a technical one. We want the user to decide to install. We’ll come back to it.</li></ul><h3>Step 2: The service worker</h3><p>The whole worker is small. Its job is to precache the shell and answer every navigation with it.</p><pre>// src/sw.ts<br>/// &lt;reference lib=&quot;webworker&quot; /&gt;<br>import { cleanupOutdatedCaches, matchPrecache, precacheAndRoute } from &quot;workbox-precaching&quot;;<br>import { NavigationRoute, registerRoute } from &quot;workbox-routing&quot;;<br><br>declare const self: ServiceWorkerGlobalScope;<br><br>// Vite-plugin-pwa replaces __WB_MANIFEST with the list of built files + hashes.<br>precacheAndRoute(self.__WB_MANIFEST);<br>cleanupOutdatedCaches();<br><br>// A new worker waits until the page says so, so an update<br>// never takes over in the middle of an edit.<br>self.addEventListener(&quot;message&quot;, (event) =&gt; {<br>  if (event.data?.type === &quot;SKIP_WAITING&quot;) void self.skipWaiting();<br>});<br><br>// Single-page app: every navigation gets the shell. If even that is<br>// missing, fall back to a tiny static offline page.<br>registerRoute(<br>  new NavigationRoute(async () =&gt; {<br>    const shell = await matchPrecache(&quot;/index.html&quot;);<br>    if (shell) return shell;<br>    return (await matchPrecache(&quot;/offline.html&quot;)) ?? Response.error();<br>  }),<br>);</pre><p>Why this works: React Router handles /boards/abc on the client, so the server never has a file for it. By answering <strong>every</strong> navigation with the cached index.html, deep links work offline too.</p><p>offline.html is the last resort: if someone opens the app for the very first time with no connection, there is no shell to serve. A static page with a <em>Try again</em> button is better than the browser’s dinosaur. Keep it free of any JavaScript bundle, because it has to work when nothing else does.</p><h4>Don’t let your host cache the wrong things</h4><p>The service worker and the HTML must never be cached by the CDN, or users will be stuck on old versions. Hashed assets, on the other hand, can be cached forever. This project is deployed to Firebase hosting, in firebase.json:</p><pre>&quot;headers&quot;: [<br>  { &quot;source&quot;: &quot;/sw.js&quot;,         &quot;headers&quot;: [{ &quot;key&quot;: &quot;Cache-Control&quot;, &quot;value&quot;: &quot;no-cache&quot; }] },<br>  { &quot;source&quot;: &quot;/index.html&quot;,    &quot;headers&quot;: [{ &quot;key&quot;: &quot;Cache-Control&quot;, &quot;value&quot;: &quot;no-cache&quot; }] },<br>  { &quot;source&quot;: &quot;/offline.html&quot;,  &quot;headers&quot;: [{ &quot;key&quot;: &quot;Cache-Control&quot;, &quot;value&quot;: &quot;no-cache&quot; }] },<br>  { &quot;source&quot;: &quot;/assets/**&quot;,     &quot;headers&quot;: [{ &quot;key&quot;: &quot;Cache-Control&quot;, &quot;value&quot;: &quot;public, max-age=31536000, immutable&quot; }] }<br>]</pre><p>This is the single most common cause of “I deployed but nothing changed” with PWAs. In the above firebase.json, assets has been set to immutable, because the expectation is it will not be updated too often.</p><h3>Step 3: Offline data with Firestore</h3><p>The shell loads offline, but a board with no cards is useless. Firestore has a built-in persistent cache backed by IndexedDB. It serves previously read documents when offline, and it queues writes and replays them on reconnect.</p><pre>// src/firebase/firebase.ts<br>import {<br>  initializeFirestore, getFirestore, memoryLocalCache,<br>  persistentLocalCache, persistentMultipleTabManager,<br>} from &quot;firebase/firestore&quot;;<br><br>function createFirestore() {<br>  try {<br>    if (typeof indexedDB === &quot;undefined&quot;) throw new Error(&quot;no persistent cache&quot;);<br>    return initializeFirestore(app, {<br>      localCache: persistentLocalCache({<br>        tabManager: persistentMultipleTabManager(), // several tabs share one cache<br>      }),<br>    });<br>  } catch {<br>    try {<br>      return initializeFirestore(app, { localCache: memoryLocalCache() });<br>    } catch {<br>      return getFirestore(app); // already initialised (hot reload)<br>    }<br>  }<br>}<br><br>export const db = createFirestore();</pre><p>Notes:</p><ul><li>persistentMultipleTabManager matters. Without it, a second open tab fails to get the IndexedDB lock.<br>- <strong>The fallback to </strong>memoryLocalCache keeps the app working in private modes and old browsers where IndexedDB is refused. You lose offline, not the app.<br>- <strong>Your UI code doesn’t change.</strong> onSnapshot listeners keep firing with cached data, and writeBatch(…).commit() resolves locally. Only the sync is deferred.</li></ul><h4>What offline does not cover: uploads</h4><p>Firestore queues writes silently, but file uploads to Cloud Storage fail loudly when offline. We treat that as a feature. Uploads check connectivity first and say so plainly:</p><pre>export async function addAttachment(args: {...}) {<br>  if (isOffline()) throw new OfflineError();   // &quot;Adding files needs a connection&quot;<br>  // 1. upload the file<br>  // 2. only then write the record + count in one batch<br>}</pre><p>Its important to note, order matters here too: <strong>upload first, write the record second</strong>. A Firestore write succeeds instantly offline, so if you wrote the record first you would show a file that doesn’t exist.</p><h3>Step 4: An honest connection indicator</h3><p>navigator.onLineonly says whether the device has a network interface up. A hotel wifi page, a dead VPN or a flaky tunnel all report `true` while nothing works. We combine two signals.</p><p><strong>Signal 1: the browser’s events.</strong></p><pre>const subscribeOnline = (set: (online: boolean) =&gt; void) =&gt; {<br>  const update = () =&gt; set(navigator.onLine);<br>  window.addEventListener(&quot;online&quot;, update);<br>  window.addEventListener(&quot;offline&quot;, update);<br>  return () =&gt; {<br>    window.removeEventListener(&quot;online&quot;, update);<br>    window.removeEventListener(&quot;offline&quot;, update);<br>  };<br>};</pre><p><strong>Signal 2: ask Firestore. </strong>Listen to the signed-in person’s own member document with includeMetadataChanges. If the snapshot keeps coming fromCache, the server is out of reach:</p><pre>const UNREACHABLE_AFTER_MS = 2500;<br><br>stopDoc = onSnapshot(<br>  doc(db, &quot;members&quot;, user.email.toLowerCase()),<br>  { includeMetadataChanges: true },<br>  (snap) =&gt; {<br>    if (!snap.metadata.fromCache) {<br>      clearTimeout(timer); timer = undefined;<br>      setUnreachable(false);<br>    } else {<br>      timer ??= setTimeout(() =&gt; setUnreachable(true), UNREACHABLE_AFTER_MS);<br>    }<br>  },<br>);</pre><p>The timeout avoids flicker: a snapshot is briefly fromCache on every page load before the server answers.</p><p>We will also show <em>Syncing changes</em> if writes are pending, using waitForPendingWrites plus a 400 ms delay so normal fast writes never flash a notice. Then one tiny module shares the result with non-React code:</p><pre>// src/pwa/connectivity.ts<br>let serverUnreachable = false;<br>export const setServerUnreachable = (v: boolean) =&gt; { serverUnreachable = v; };<br>export const isOffline = () =&gt;<br>  (typeof navigator !== &quot;undefined&quot; &amp;&amp; !navigator.onLine) || serverUnreachable;</pre><p>The header text is deliberately calm: nothing when online and in sync, <em>Syncing changes</em> while writes drain, and <em>Offline. Changes will sync when you reconnect</em> when offline with edits waiting.</p><h3>Step 5: Installing the app</h3><h4><strong>Chromium (desktop and Android)</strong></h4><p>Chromium fires beforeinstallprompt once, early, possibly before React mounts. If you listen inside a component you will miss it. So we capture it in a module that starts listening on import, and expose it through useSyncExternalStore:</p><pre>// src/pwa/install.ts<br>import { useSyncExternalStore } from &quot;react&quot;;<br><br>type PromptEvent = Event &amp; {<br>  prompt: () =&gt; Promise&lt;void&gt;;<br>  userChoice: Promise&lt;{ outcome: string }&gt;;<br>};<br><br>type State = { event: PromptEvent | null; installed: boolean };<br>let state: State = { event: null, installed: isInstalledApp() };<br>const listeners = new Set&lt;() =&gt; void&gt;();<br>const set = (next: Partial&lt;State&gt;) =&gt; {<br>  state = { ...state, ...next };<br>  listeners.forEach((l) =&gt; l());<br>};<br><br>window.addEventListener(&quot;beforeinstallprompt&quot;, (e) =&gt; {<br>  e.preventDefault();                       // hide the browser&#39;s own mini-bar<br>  set({ event: e as PromptEvent });<br>});<br>window.addEventListener(&quot;appinstalled&quot;, () =&gt; set({ event: null, installed: true }));<br><br>async function install() {<br>  const { event } = state;<br>  if (!event) return;<br>  set({ event: null });                     // the event works only once<br>  await event.prompt();<br>  await event.userChoice;<br>}<br><br>export function useInstall() {<br>  const { event, installed } = useSyncExternalStore(<br>    (l) =&gt; (listeners.add(l), () =&gt; listeners.delete(l)),<br>    () =&gt; state,<br>  );<br>  return { canInstall: !!event &amp;&amp; !installed, installed, install };<br>}</pre><p>Import this file first in main.tsx, so the listener exists before anything else runs. The button then renders only when the browser says installation is possible:</p><pre>export function InstallButton() {<br>  const { canInstall, install } = useInstall();<br>  if (!canInstall) return null;<br>  return &lt;IconButton label=&quot;Install app&quot; icon={Download} onClick={() =&gt; void install()} /&gt;;<br>}</pre><p>No dead button, no button after install.</p><h4>iOS Safari</h4><p>iOS has no install prompt. The only route is Share, then Add to Home Screen. So we detect iOS Safari and show a dismissible hint once. Detection has one quirk: iPadOS reports itself as a Mac, so touch points tell it apart.</p><pre>export function isIosSafari(): boolean {<br>  const ua = navigator.userAgent;<br>  const ios = /iPhone|iPad|iPod/.test(ua) ||<br>    (/Macintosh/.test(ua) &amp;&amp; navigator.maxTouchPoints &gt; 1);<br>  const otherBrowser = /CriOS|FxiOS|EdgiOS|OPiOS|GSA/.test(ua);<br>  return ios &amp;&amp; !otherBrowser &amp;&amp; /Safari/.test(ua);<br>}<br><br>export function isInstalledApp(): boolean {<br>  if ((navigator as any).standalone === true) return true;   // iOS Home Screen flag<br>  return window.matchMedia?.(&quot;(display-mode: standalone)&quot;).matches ?? false;<br>}</pre><p>The dismissal is remembered in localStorage, wrapped in try/catch, because private mode can throw. If it fails, the hint simply returns next visit.</p><h3>Step 6: Updates that never interrupt an edit</h3><p>The default PWA behaviour, skipWaiting() plus clients.claim(), swaps in a new service worker immediately. If the new version expects different data or a different chunk layout, a user mid-edit gets a broken page.</p><p>We chose the opposite: a new worker installs and <strong>waits</strong>. The page shows a small notice, and the user decides when to reload.</p><pre>// src/pwa/UpdatePrompt.tsx<br>import { useRegisterSW } from &quot;virtual:pwa-register/react&quot;;<br><br>export function UpdatePrompt() {<br>  const { needRefresh: [needRefresh], updateServiceWorker } = useRegisterSW();<br>  if (!needRefresh) return null;<br>  return (<br>    &lt;div role=&quot;status&quot; className=&quot;fixed inset-x-4 bottom-4 ...&quot;&gt;<br>      &lt;span&gt;Update available&lt;/span&gt;<br>      &lt;IconButton label=&quot;Reload&quot; icon={RefreshCw} tone=&quot;primary&quot;<br>                  onClick={() =&gt; updateServiceWorker(true)} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Pressing Reload sends the SKIP_WAITING message our worker listens for (Step 2), and the page reloads under the new version.</p><h4>The escape hatch: Refresh app</h4><p>Sometimes a user is stuck on an old build and no prompt appears. We added a Refresh app action in Settings. It deletes this site’s caches, unregisters the worker and reloads. Importantly, it <strong>does not touch </strong>sign-in or Firestore’s offline data, and it warns first if edits are still waiting to sync.</p><pre>// src/pwa/refresh.ts<br>export async function hasUnsyncedEdits(waitMs = 500): Promise&lt;boolean&gt; {<br>  let timer: ReturnType&lt;typeof setTimeout&gt; | undefined;<br>  const stillWaiting = new Promise&lt;true&gt;((r) =&gt; { timer = setTimeout(() =&gt; r(true), waitMs); });<br>  const synced = waitForPendingWrites(db).then(() =&gt; false as const, () =&gt; false as const);<br>  try { return await Promise.race([synced, stillWaiting]); }<br>  finally { clearTimeout(timer); }<br>}<br><br>export async function refreshApp(): Promise&lt;void&gt; {<br>  if (typeof caches !== &quot;undefined&quot;) {<br>    await Promise.all((await caches.keys()).map((name) =&gt; caches.delete(name)));<br>  }<br>  const registration = await navigator.serviceWorker?.getRegistration();<br>  await registration?.unregister();<br>  reloadApp();<br>}</pre><p>waitForPendingWrites resolves when the server has acknowledged everything. Racing it against a short timer turns it into a yes/no answer: <em>is something still waiting?</em> When online, a write is acknowledged within moments, so a 500 ms wait is enough.</p><p>We also bake the short git commit into the build (define: { __APP_VERSION__: … }) and show it in Settings. When someone says <em>it’s still broken</em>, the first question, <em>which version?</em>, has a one-glance answer by referring to the version and usually the las 2 digits are enough to check if the system is unique.</p><h3>Step 7: Cache hygiene</h3><p>Two details keep the app light and safe.</p><h4>Don’t precache the heavy, rarely-used code</h4><p>The sketch editor that I planned to use in my kanban board (Excalidraw) is large. Precaching it would make <strong>installing</strong> the app slow for everyone, even people who never draw. So we exclude it from the precache and cache it the first time it is used:</p><pre>const SKETCH_EDITOR_CACHE = &quot;sketch-editor&quot;;<br><br>const cacheFirst = (dropOlderHashes: boolean) =&gt;<br>  async ({ request }: { request: Request }) =&gt; {<br>    const cache = await caches.open(SKETCH_EDITOR_CACHE);<br>    const hit = await cache.match(request);<br>    if (hit) return hit;<br>    const response = await fetch(request);<br>    if (response.ok) {<br>      if (dropOlderHashes) {<br>        // a new build&#39;s chunk replaces the old hash of the same chunk<br>        const name = chunkName(new URL(request.url).pathname);<br>        for (const old of await cache.keys()) {<br>          if (chunkName(new URL(old.url).pathname) === name) await cache.delete(old);<br>        }<br>      }<br>      await cache.put(request, response.clone());<br>    }<br>    return response;<br>  };<br><br>registerRoute(({ url }) =&gt; url.pathname.startsWith(&quot;/assets/sketch-editor/&quot;), cacheFirst(true));</pre><p>To route by path, we need those chunks to <strong>live</strong> under a distinct path. Rollup’s chunkFileNames lets us place them under assets/sketch-editor/, so the service worker can tell them apart with a simple `startsWith`. Cache-first is safe because the file names carry a content hash, so a name never changes meaning.</p><p>The result: a sketch opened once online opens again offline, and the install stays light.</p><h4>Wipe cached data on sign-out</h4><p>Firestore’s IndexedDB cache outlives the session. On a shared device, the next person could see the previous person’s boards offline. So sign-out requests a wipe, and the next load performs it before serving any cached data:</p><pre>export function startOfflineCache(clear: () =&gt; Promise&lt;void&gt;) {<br>  const pending = hasWipeRequest();<br>  const done = pending<br>    ? clear().then(() =&gt; clearWipeRequest(), () =&gt; { /* keep it: retry next load */ })<br>    : Promise.resolve();<br>  return { pending, servePersistent: !pending, done };<br>}</pre><p>While a wipe is pending, the app uses the in-memory cache instead of the persistent one. The request is only dropped once the delete actually succeeded; if another tab holds the database open, it stays and retries on the next load. The same mechanism applies when a team member is removed: they lose access on reconnect, and their cache is cleared.</p><h4>Testing it</h4><p>Offline behaviour is easy to break quietly, so we test at three levels:</p><ul><li><strong>Unit tests</strong> for the install state machine, the iOS detection, the update prompt and the cache-wipe logic.</li><li><strong>Emulator tests</strong> (Firebase emulators) for rules and data flows.</li><li><strong>Playwright</strong> for end-to-end flows, including going offline with <em>context.setOffline(true)</em>.</li></ul><p>One honest caveat: automated tests tell you the logic is right, but a PWA still needs real devices. You will need to install it on an actual phone, put it in airplane mode, and open it. I recommend doing that before every release that touches the service worker t make sure that everythig works a expected.</p><h4>Lessons learned</h4><ol><li><strong>Separate code caching from data caching.</strong> They are different tools solving different problems.</li><li><strong>Make updates the user’s choice.</strong> A prompt costs one tap. A broken mid-edit reload costs trust.</li><li><strong>Never trust navigator.onLine alone.</strong> Ask the server you actually depend on. Don’t just trust navigtor.onLine to check.</li><li><strong>Capture `beforeinstallprompt` at import time</strong>, not in a component.</li><li><strong>Give people an escape hatch.</strong> <em>Refresh app</em> plus a visible version number saves hours of support.</li><li><strong>Be explicit about what doesn’t work offline.</strong> Saying <em>Adding files needs a connection</em> is kinder than a silent failure.</li><li><strong>Treat the offline cache as sensitive data.</strong> Wipe it on sign-out.</li></ol><h3>Conclusion</h3><p>None of these pieces is complicated alone. The service worker is only about forty lines. The install logic is about fifty. Offline data is a configuration option. The craft is in how they fit together: an app that opens instantly, tells the truth about its connection, never changes under your hands, and can be installed like any other app on your device.</p><p>If you are planning to build something similar, start with the shell and the manifest, get all the installation matters sorted, then add data persistence, and only then polish the edges as you go. At least the PWA part is done.</p><p><em>Selamat Mengaturcara.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05aae4aab21b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/building-an-offline-first-installable-web-app-with-react-firebase-and-workbox-05aae4aab21b">Building an Offline-First, Installable Web App with React, Firebase and Workbox</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Login Button Every Malaysian Developer Should Be Adding]]></title>
            <link>https://razmans.medium.com/the-login-button-every-malaysian-developer-should-be-adding-d640486ca321?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/d640486ca321</guid>
            <category><![CDATA[mydigitalid]]></category>
            <category><![CDATA[malaysia]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 04:50:20 GMT</pubDate>
            <atom:updated>2026-10-27T04:50:20.651Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>A practical guide to MyDigital ID SSO for Malaysian developers, with a small TypeScript package to make it painless.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*voPBN3Zxv3AWzIEh" /><figcaption>Photo by <a href="https://unsplash.com/@shotbywoliul?utm_source=medium&amp;utm_medium=referral">Woliul Hasan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Every Malaysian developer has built the same signup flow: email, password, a verification email, a <em>forgot password</em> page, and later a manual check to see whether the person is who they say they are.</p><p>For services that need to know a user’s real identity, such as fintech, government-linked services, healthcare, education or e-commerce with age or identity checks, that flow is slow and easy to fake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*d6wKOR4LrtCDuAoRDF1NzA.png" /></figure><p>MyDigital ID is Malaysia’s national digital identity. It lets you replace most of that flow with one button.</p><p>In this article I’ll cover:</p><p>1. Why MyDigital ID is worth integrating</p><p>2. What the developer portal gives you</p><p>3. How to add it to a web app with `mydigitalid-sso`, a small TypeScript package</p><p>4. How to test it, and what to watch out for</p><h4><strong>Why MyDigital ID is worth it, for Malaysians particularly:</strong></h4><h4><strong>For Malaysian users:</strong></h4><p>- <strong>One identity everywhere.</strong> They sign in with the identity they already have and don’t create another password.</p><p>- <strong>Less typing.</strong> Their details come from the identity provider, so they don’t retype their name and IC number on every form.</p><p>- <strong>Familiar flow.</strong> Login happens on a MyDigital ID page, so users learn the flow once and reuse it across services.</p><h4><strong>For developers and businesses:</strong></h4><p>- <strong>Verified identity, not self-declared. </strong>You receive claims from the identity provider instead of trusting a form field. In my integration the token carries the user’s NRIC (`nric`), full name (`nama`), given name and family name.</p><p>- <strong>No password storage.</strong> You never store or reset a password, so you have no credentials to leak.</p><p>- <strong>Standards-based.*</strong>MyDigital ID SSO speaks OpenID Connect and is Keycloak-based. If you’ve integrated Google or any OIDC provider, the concepts are the same, and mature libraries already exist.</p><p>- <strong>Less KYC friction.</strong> Fewer drop-offs at signup, and fewer manual identity checks for your ops team.</p><h4><strong>The developer website</strong></h4><p>MyDigital ID has a dedicated developer portal at <a href="https://developer.digital-id.my/">developer.digital-id.my</a>. It describes itself as a central hub to integrate, test and manage services powered by the MyDigital ID ecosystem.</p><p>Based on the explanation on he developer’s portal, here is a sensible order of how the authentication process is done:</p><ol><li>Request or register your application to get a <strong>realm </strong>and a <strong>client ID</strong>.</li><li>Register your <strong>redirect URIs</strong>, including <em>http://localhost:8080</em> for development.</li><li>Run the sample code to see a working flow.</li><li>Then wire it into your own app.</li></ol><p>Do step 2carefully. Most “it doesn’t redirect back” problems come from a redirect URI that doesn’t exactly match what’s registered.</p><h4><strong>Using mydigitalid-sso npm library that I made</strong></h4><p>The portal’s sample code uses the Keycloak JavaScript adapter directly. That works, but I kept re-writing the same glue: token restore, profile mapping, refresh, logout cleanup. So I turned it into a small typed package, <a href="https://www.npmjs.com/package/mydigitalid-sso?activeTab=readme"><strong>mydigitalid-sso</strong></a>. It wraps keycloak-js and gives you a clean API.</p><p>What it does:</p><p>- Connects to https://sso.digital-id.my by default and uses the standard flow with PKCE</p><p>- Restores an existing SSO session on page load (silent check-sso)</p><p>- Logs in, logs out and refreshes tokens</p><p>- Maps claims to a typed profile</p><p>- Optionally persists the session across reloads</p><p>- Ships ESM, CJS and TypeScript types</p><p>It is for <strong>public clients in the browser</strong>. It has no client-secret option, and that is deliberate: a secret, if it is in the front-end code, isn’t a secret. Try to look at it like a pocketwatch. If you give the pocketwatch to a user, a user can take it apart and, for a lack of a better metaphor, see what makes it tick.</p><h4><strong>1. Install</strong></h4><pre>npm install mydigitalid-sso</pre><h4><strong>2. Add the silent check page</strong></h4><p>Copy one tiny file into your web root so it’s served at /checksso.html:</p><pre>cp node_modules/mydigitalid-sso/public/checksso.html ./public/checksso.html</pre><p>This lets the library check for an existing SSO session in the background, without a full-page redirect.</p><h4><strong>3. Create the client</strong></h4><pre>import { createMyDigitalIdClient } from “mydigitalid-sso”;<br><br>const id = await createMyDigitalIdClient({<br>  realm: “your-realm”,<br>  clientId: “your-public-client”,<br>  persistSession: true, // optional<br>});</pre><h4><strong>4. Log in and read the profile</strong></h4><pre>if (id.authenticated) {<br>  const { nric, fullName, givenName, familyName, expiresAt } = id.getProfile()!;<br>  console.log(`Welcome, ${fullName}`);<br>} else {<br>  await id.login(); // redirects to MyDigital ID, then back to your page<br>}</pre><p>That’s the whole login flow. The user is redirected, authenticates with MyDigital ID, and comes back signed in.</p><h4><strong>5. Refresh and log out</strong></h4><pre>await id.refreshToken(); // refresh if expiring within 30 seconds<br>await id.refreshToken(-1); // force a refresh<br>await id.logout(); // clears local session and signs out</pre><h4><strong>6. Call your backend</strong></h4><pre>await fetch(“/api/me”, {<br>  headers: { Authorization: `Bearer ${id.tokens.token}` },<br>});</pre><p><strong>Verify the token on your server.</strong> Check the signature, issuer, audience and expiry against the provider’s published keys. Never trust claims you only decoded in the browser.</p><h4><strong>Testing it</strong></h4><p>The package has two layers of testing.</p><ol><li><strong>Unit tests </strong>(no network):</li></ol><pre>npm install<br>npm test</pre><p>They cover claim mapping, JWT decoding, config validation, idempotent `init`, session persist, restore and expiry, logout cleanup and refresh. `keycloak-js` is mocked, so they run in under a second.</p><p><strong>2. A playground against the real SSO:</strong></p><pre>npm run playground #http://localhost:8080</pre><p>1. Register http://localhost:8080 as a redirect URI for your client.</p><p>2. Open the page and enter your realm and client ID.</p><p>3. Click <strong>Log in</strong>. After the redirect you’ll see NRIC, names and token expiry.</p><p>4. Try <strong>Force refresh token</strong>, <strong>Show claims</strong> and <strong>Log out</strong>, and reload to check session restore.</p><h4><strong>Pitfalls I hit</strong></h4><p>- <strong>Redirect URI mismatch.</strong> It must match exactly, including scheme, host, port and trailing slash.</p><p>- <strong>Missing checksso.html.</strong> Without it, silent session checks fail. Make sure it’s served from your origin.</p><p>- <strong>Secrets in the browser. </strong>My original test page stored a client secret in a cookie, and the adapter never used it. Drop it.</p><p>- <strong>Tokens in storage. </strong>sessionStorage is readable by any script on your page, so persistSession is off by default. Turn it on only if you accept that trade-off.</p><p>- <strong>Decoding is not verifying.</strong> decodeJwt is for display. Authorise on the server.</p><h4><strong>Wrapping up</strong></h4><p>MyDigital ID gives Malaysian apps something email and password can’t: a login backed by a real, verified national identity. The developer portal gets you registered and shows you the flow. A small wrapper like mydigitalid-sso removes the repetitive part, so adding it takes minutes.</p><p>If you build something with it, I’d like to hear how it goes and to see if it works.</p><p><em>Disclosure: `mydigitalid-sso` is an independent, community-style wrapper and is not an official MyDigital ID product. Check the official developer portal for the latest requirements and policies.</em></p><p><em>Selamat Mengaturcara</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d640486ca321" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAZ Encrypt: Post-Quantum Cryptography in 10 Lines of JavaScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/raz-encrypt-post-quantum-cryptography-in-10-lines-of-javascript-eb875d491d58?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*hlhlqSVxSwrUroVa" width="3999"></a></p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/raz-encrypt-post-quantum-cryptography-in-10-lines-of-javascript-eb875d491d58?source=rss-a71f56d30305------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/raz-encrypt-post-quantum-cryptography-in-10-lines-of-javascript-eb875d491d58?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb875d491d58</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[post-quantum-cryptography]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 14:41:30 GMT</pubDate>
            <atom:updated>2026-09-23T14:41:30.953Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Running a Local LLM on My Old Android Phone: A Complete Journal]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/running-a-local-llm-on-my-old-android-phone-a-complete-journal-25cb30e07c53?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*OT6dbNROowWUZxTf" width="2800"></a></p><p class="medium-feed-snippet">From &#x201C;can my phone even run an AI model&#x201D; to a working, searchable, auto-starting local LLM server with all the errors, dead ends, and&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/running-a-local-llm-on-my-old-android-phone-a-complete-journal-25cb30e07c53?source=rss-a71f56d30305------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/running-a-local-llm-on-my-old-android-phone-a-complete-journal-25cb30e07c53?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/25cb30e07c53</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[self-hosted]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Fri, 28 Aug 2026 17:25:55 GMT</pubDate>
            <atom:updated>2026-08-28T17:25:55.102Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Keep Your Python Scripts Running Forever: PM2, systemd, and Supervisor Compared]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/keep-your-python-scripts-running-forever-pm2-systemd-and-supervisor-compared-6162f2e92238?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*Fk2wHDci11Uz_-r5" width="6058"></a></p><p class="medium-feed-snippet">Photo by Felicia Montenegro on Unsplash</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/keep-your-python-scripts-running-forever-pm2-systemd-and-supervisor-compared-6162f2e92238?source=rss-a71f56d30305------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/keep-your-python-scripts-running-forever-pm2-systemd-and-supervisor-compared-6162f2e92238?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/6162f2e92238</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 04:32:23 GMT</pubDate>
            <atom:updated>2026-07-20T14:43:32.314Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Firestore Security Rules: Templates Every Developer Should Know]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/firestore-security-rules-templates-every-developer-should-know-546a33f0f00f?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*o8yyE5hz5Ejvkxtb" width="4000"></a></p><p class="medium-feed-snippet">Stop shipping apps with Firestore rules like this- allow read, write: if true</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/firestore-security-rules-templates-every-developer-should-know-546a33f0f00f?source=rss-a71f56d30305------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/firestore-security-rules-templates-every-developer-should-know-546a33f0f00f?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/546a33f0f00f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Mon, 13 Jul 2026 15:31:16 GMT</pubDate>
            <atom:updated>2026-07-13T15:31:16.910Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Build a Modern Browser Extension in 2026: Start with the Best Boilerplate]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/how-to-build-a-modern-browser-extension-in-2026-start-with-the-best-boilerplate-67a1626e87ae?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*lYOiFg_nVHH6bi2d" width="6000"></a></p><p class="medium-feed-snippet">Creating a browser extension used to mean wrestling with complex configurations, Manifest V3 rules, and build tools. This is not the case&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/how-to-build-a-modern-browser-extension-in-2026-start-with-the-best-boilerplate-67a1626e87ae?source=rss-a71f56d30305------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/how-to-build-a-modern-browser-extension-in-2026-start-with-the-best-boilerplate-67a1626e87ae?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/67a1626e87ae</guid>
            <category><![CDATA[browser-extension]]></category>
            <category><![CDATA[vitejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[boilerplate]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Mon, 20 Apr 2026 15:58:31 GMT</pubDate>
            <atom:updated>2026-04-20T15:58:31.232Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Securely Access Your OpenClaw AI Agent Dashboard from Anywhere Using SSH Tunneling]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://razmans.medium.com/how-to-securely-access-your-openclaw-ai-agent-dashboard-from-anywhere-using-ssh-tunneling-b4dad8aa5c46?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*BmKOR3LlKfPIQL09" width="11339"></a></p><p class="medium-feed-snippet">Run your powerful local AI agent on a remote VPS while keeping the web gateway completely private and accessible only through an encrypted&#x2026;</p><p class="medium-feed-link"><a href="https://razmans.medium.com/how-to-securely-access-your-openclaw-ai-agent-dashboard-from-anywhere-using-ssh-tunneling-b4dad8aa5c46?source=rss-a71f56d30305------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://razmans.medium.com/how-to-securely-access-your-openclaw-ai-agent-dashboard-from-anywhere-using-ssh-tunneling-b4dad8aa5c46?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4dad8aa5c46</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[port-forwarding]]></category>
            <category><![CDATA[openclaw]]></category>
            <category><![CDATA[ssh-tunnel]]></category>
            <category><![CDATA[self-hosting]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Tue, 14 Apr 2026 01:41:01 GMT</pubDate>
            <atom:updated>2026-04-14T01:41:01.845Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Ionic React: Navigating from page to page]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://razmans.medium.com/ionic-react-navigating-from-page-to-page-f3443f3f9477?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*-PzujMmDAwK21Cka" width="6000"></a></p><p class="medium-feed-snippet">Photo by Fili Santill&#xE1;n on Unsplash</p><p class="medium-feed-link"><a href="https://razmans.medium.com/ionic-react-navigating-from-page-to-page-f3443f3f9477?source=rss-a71f56d30305------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://razmans.medium.com/ionic-react-navigating-from-page-to-page-f3443f3f9477?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3443f3f9477</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 09:07:22 GMT</pubDate>
            <atom:updated>2026-04-08T09:07:22.938Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[5 Reasons to Use NGXS in an Angular Project]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://razmans.medium.com/5-reasons-to-use-ngxs-in-an-angular-project-4abee075787b?source=rss-a71f56d30305------2"><img src="https://cdn-images-1.medium.com/max/2600/0*lLT6Tt4tUp0QF0MW" width="5300"></a></p><p class="medium-feed-snippet">Why Use NGXS State Management?</p><p class="medium-feed-link"><a href="https://razmans.medium.com/5-reasons-to-use-ngxs-in-an-angular-project-4abee075787b?source=rss-a71f56d30305------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://razmans.medium.com/5-reasons-to-use-ngxs-in-an-angular-project-4abee075787b?source=rss-a71f56d30305------2</link>
            <guid isPermaLink="false">https://medium.com/p/4abee075787b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[RYMS]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 09:06:06 GMT</pubDate>
            <atom:updated>2026-04-08T09:06:06.331Z</atom:updated>
        </item>
    </channel>
</rss>