Posts

Showing posts with the label Broswer API

Stop Your Blazor Tabs from Fighting with the Web Locks API

Image
As .NET developers, our instinct when dealing with concurrency is to look at the backend: optimistic locking in Entity Framework, Redis distributed locks, or background queue orchestration. We rarely think about client-side concurrency until a user opens our application across three separate browser tabs. Suddenly, all three tabs trigger a local cache warmup, attempt to flush an IndexedDB offline queue simultaneously, and trigger duplicate background sync calls. Before building an ad-hoc coordination protocol over localStorage events or BroadcastChannel, look at what the browser already provides: the Web Locks API (navigator.locks). How Web Locks Work The Web Locks API acts as an origin-wide mutex across tabs, windows, and Web Workers. Instead of managing lock acquisition and manual teardown, you pass a callback to navigator.locks.request(). The browser grants the lock, executes your async callback, and releases the lock the moment the returned promise resolves or rejects. JavaScript a...