Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
An Offline-Capable App with the Angular Service Worker: ngsw-config, dataGroups, SwUpdate and Safe Deploys
The Angular Service Worker caches app files with assetGroups and API responses with dataGroups, and detects versions from the hashed ngsw.json the build produces; you announce a new version with SwUpdate.versionUpdates and let the user do a full reload. On a production build we show the offline scenario, VERSION_READY, the unrecoverable state after old files are deleted, deploy cache headers and withdrawing the worker with safety-worker.js in Chromium and WebKit.
The Service Worker Lifecycle and Caching Strategies: install, activate, waiting, skipWaiting and Stale-While-Revalidate
A new service worker waits in waiting until every tab of the old version closes or skipWaiting is called; reloading the only tab is not enough. With a framework-free worker we walk through the lifecycle in Chromium and WebKit, and look at skipWaiting mixing an old page with a new chunk, updateViaCache, cache-first/network-first/stale-while-revalidate strategies, the HTTP cache trap and a kill switch that withdraws the worker.
Using IndexedDB in Angular: Schema Versioning, Transactions and an Offline Outbox
In IndexedDB the schema changes only inside onupgradeneeded when the version goes up, and a transaction commits by itself at an await that is not IndexedDB; so the network work comes first and the writes after. We show per-version migrations, TransactionInactiveError and another tab blocking an upgrade in Chromium and WebKit, then build the reading list with idb in Angular and an outbox that sends offline reviews without duplicates using idempotency keys.