C# / .NET Compendium PLEN
.NET / C# / Web API, Blazor

PWA (Progressive Web App) in the context of Blazor

What a PWA is - in general

A PWA is a set of web techniques that make a website behave like a native application: it can be "installed" (an icon on the desktop/home screen), can work (partly) offline, can send push notifications, and opens in a separate window without the browser's address bar.

Key elements of a PWA

1. The Web App Manifest (manifest.json) - application metadata:

{
  "name": "Order Management System",
  "short_name": "OrderMgmt",
  "start_url": "/",
  "display": "standalone",
  "icons": [
    { "src": "icon-512.png", "sizes": "512x512", "type": "image/png" }
  ]
}

This lets the browser show an "Install app" option and makes it open like a native window, without the browser UI.

2. The Service Worker - a JS script running in the background, independent of an open tab, intercepting network requests:

// service-worker.js (a simplified example)
self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(cached => cached || fetch(event.request))
  );
});

The Service Worker caches static files (HTML, CSS, JS, and in the case of Blazor WASM - the compiled .NET assemblies too), so the application can load and partly work without an internet connection.

PWA + Blazor WebAssembly - a natural combination

This is an important conceptual point: a PWA makes practical sense mainly with Blazor WASM, not with Blazor Server.

Why: - Blazor WASM runs all the application code locally in the browser (compiled to WebAssembly) - if those files are cached by the Service Worker, the application can actually work offline (the UI renders, local logic works) - Blazor Server requires a persistent WebSocket connection to the server (the whole "circuit" and state live on the server) - offline makes no sense at all, because without a connection nothing can run (even clicking a button requires a round trip to the server)

dotnet new blazorwasm --pwa -o MyApp

This template generates a Blazor WASM project with a ready-made manifest.json and service-worker.js.

The limitations of a PWA with Blazor WASM in practice

  • Data requiring a backend (a database, server-side authorisation) won't work offline anyway - a PWA gives offline for the UI and local logic, not for operations requiring a server
  • Synchronising data after coming back online requires your own logic (e.g. queueing changes locally and sending them once the connection returns) - Blazor doesn't do this automatically
  • The download size is larger (the whole .NET runtime for WASM), so the first offline-first load can be slower than a classic SPA in pure JS

Render Modes in Blazor (.NET 8+) - "Blazor United"

This is one of the biggest architectural turns in Blazor - .NET 8 merged Blazor Server and WASM into one model, with the ability to choose the rendering mode per component.

Four rendering modes

1. Static Server Rendering (SSR) - the default, no interactivity

@page "/orders"
@rendermode InteractiveServer  <!-- lub brak = static -->

Rendered once on the server to static HTML and sent to the browser. No interactivity - no @onclick, no C# state running on the client side. It is like classic, traditional server-rendered HTML (similar to old Razor Pages/MVC).

When: content pages (a blog, documentation, a landing page) - fast, with no SignalR/WASM overhead.

2. Interactive Server

@page "/orders"
@rendermode InteractiveServer

This is exactly the Blazor Server model I described above - SignalR, a circuit on the server, all the C# logic runs server-side.

When: applications that need a fast time to first interaction (you don't wait for the WASM download), where constant network traffic isn't a problem (e.g. internal company tools, an intranet).

3. Interactive WebAssembly

@page "/orders"
@rendermode InteractiveWebAssembly

This is classic Blazor WASM as described earlier - the code is downloaded and executed in the browser.

When: you need a PWA/offline, you want to offload the server (the logic runs at the client), a public application with many concurrent users (you don't worry about circuits/server memory).

4. Interactive Auto - "the best of both worlds"

@page "/orders"
@rendermode InteractiveAuto

The most interesting, new mode: on the first page load it uses Blazor Server (a fast start, no waiting for the WASM download), and quietly downloads in the background the WebAssembly files. On subsequent visits to the same application (WASM already cached in the browser) it automatically switches to WebAssembly - faster interactions, less load on the server.

This solves the classic dilemma "Server (a fast start, but dependent on the network) vs WASM (a slow start, but fast afterwards)" - the user gets a fast start the first time and fast operation every time after.

Per component, not just per application

The key flexibility of .NET 8 - different components in the same application can have different render modes:

@* Home page - static, fast, SEO-friendly *@
@page "/"
<HomePage />

@* Panel administracyjny - interaktywny, server-side *@
@page "/admin"
@rendermode InteractiveServer
<AdminDashboard />

@* A calculator in the browser - offline-capable *@
@page "/calculator"
@rendermode InteractiveWebAssembly
<Calculator />

This lets you deliberately match the technology to a specific part of the application - a marketing page needs neither SignalR nor WASM, an admin panel can use Blazor Server (few users, sensitive data better kept on the server), and a public calculator can be WASM (offline, no load on the server).

A comparison table of all the modes

Static SSR Interactive Server Interactive WASM Interactive Auto
Where the logic is The server (once) The server (all the time) The browser Server → then WASM
Interactivity ❌ None ✅ Yes ✅ Yes ✅ Yes
First load time Fastest Fast Slow (downloads WASM) Fast (like Server)
Requires a persistent connection No Yes (WebSocket) No (after loading) Depends on the phase
Offline/PWA Not applicable ❌ No ✅ Yes ✅ After switching to WASM
Server load Minimal High (state per user) Minimal (only the API) Decreasing over time

Summary - a good answer in an interview about Render Modes

"Render Modes in .NET 8 solve the age-old Blazor Server vs WASM dilemma, letting you choose the model per component instead of for the whole application. Static SSR for content without interactivity, Interactive Server when I care about a fast start and a persistent WebSocket connection isn't a problem, Interactive WebAssembly when I need a PWA/offline or want to offload the server, and Interactive Auto is the compromise - a fast start through Server on the first visit, a smooth transition to WASM on later ones, once the files are already cached."

Buy me a coffee