Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsakamoto/Toolbelt.Blazor.PWA.Updater
Provide "Update Now" UI and feature to your Blazor PWA that appears when the next version of one is available.
https://github.com/jsakamoto/Toolbelt.Blazor.PWA.Updater
Last synced: 3 months ago
JSON representation
Provide "Update Now" UI and feature to your Blazor PWA that appears when the next version of one is available.
- Host: GitHub
- URL: https://github.com/jsakamoto/Toolbelt.Blazor.PWA.Updater
- Owner: jsakamoto
- License: mpl-2.0
- Created: 2022-08-07T06:16:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T23:47:00.000Z (over 1 year ago)
- Last Synced: 2024-07-31T12:11:52.946Z (3 months ago)
- Language: HTML
- Size: 597 KB
- Stars: 130
- Watchers: 12
- Forks: 6
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazor - Blazor PWA Updater - ![stars](https://img.shields.io/github/stars/jsakamoto/Toolbelt.Blazor.PWA.Updater?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/jsakamoto/Toolbelt.Blazor.PWA.Updater?style=flat-square&cacheSeconds=86400) Provide "Update Now" UI and feature to your Blazor PWA that appears when the next version of one is available. (Libraries & Extensions / 2D/3D Rendering engines)
README
# Blazor PWA Updater [![NuGet Package](https://img.shields.io/nuget/v/Toolbelt.Blazor.PWA.Updater.svg)](https://www.nuget.org/packages/Toolbelt.Blazor.PWA.Updater/)
## 📝 Summary
Provide "Update Now" UI and feature to your Blazor PWA that appears when the next version of one is available.
![](https://raw.githubusercontent.com/jsakamoto/Toolbelt.Blazor.PWA.Updater/main/.assets/fig.001.png)
### Supported platforms
.NET 6 or later. Both Blazor Server and Blazor Assembly are supported.
## 🤔 Backgrounds
Typically, a service worker of PWA is never updated even when updated contents have been deployed to a server, even if you reload the page of that PWA. After the user has navigated away from the PWA in all tabs, updates will complete. This is not specific to Blazor, but rather is a standard web platform behavior.
For more detail, please see also the following link on the Microsoft Docs site.
[_"ASP.NET Core Blazor Progressive Web App (PWA)"_ | Miceooft Docs](https://docs.microsoft.com/aspnet/core/blazor/progressive-web-app?view=aspnetcore-6.0&tabs=visual-studio#update-completion-after-user-navigation-away-from-app)
However, sometimes, a site owner or a developer may want updates completed as soon as possible. In that case, all we can do is notify the user that the new version of the service worker is ready on the browser screen and trigger the update process via the user's manual action.
This NuGet package allows us to implement that behavior like the following GIF animation on your Blazor PWA more easily.
![](https://raw.githubusercontent.com/jsakamoto/Toolbelt.Blazor.PWA.Updater/main/.assets/movie.001.gif)
## 🚀 Quick Start
### 1. Install this NuGet package
```shell
dotnet add package Toolbelt.Blazor.PWA.Updater
```### 2. Register a "PWA updater" service to a DI container
```csharp
// 📜 This is the "Program.cs" file of your Blazor PWA.
...
// 👇 Add this line to open the name space...
using Toolbelt.Blazor.Extensions.DependencyInjection;
...
// 👇 and add this line to register a "PWA updater" service to a DI container.
builder.Services.AddPWAUpdater();
...
await builder.Build().RunAsync();
```### 3. Place a `` component somewhere in your Blazor PWA
A `` component is a user interface element showing users the "UPDATE NOW" button and its notification bar. One of the good places to place a `` component is somewhere shared layout components, such as "MainLayout.razor".
```razor
@* 📜 This is the "MainLayout.razor" file of your Blazor PWA *@
@inherits LayoutComponentBase@* 👇 Add this line to place the "UPDATE NOW" button UI. *@
...
```### 4. Modify the "service-worker.published.js" file
```js
// 📜 This is the "service-worker.published.js" file of your Blazor PWA.// 👇 Add these line to accept the message from this library.
self.addEventListener('message', event => {
if (event.data?.type === 'SKIP_WAITING') self.skipWaiting();
});
...
```### 5. Modify the "index.html" file
```html
...