发布更改后强制重新加载 Blazor 客户端 [英] Forcing reload of Blazor client after publishing changes

查看:27
本文介绍了发布更改后强制重新加载 Blazor 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Blazor 应用程序,我将其部署到 Azure 以进行一些 alpha 测试.我已经做到了,我可以从网站上运行应用程序就好了.

当我对客户端和服务器项目进行更改并重新发布它们时,问题就出现了.无论浏览器正在运行,客户端都将运行浏览器缓存中已经存在的任何内容,直到浏览器历史记录被清除.这意味着在清除历史记录之前,应用程序似乎已损坏,因为旧版本上的客户端请求与新的服务器 API 不匹配 - 更不用说我的客户端更改没有得到测试.

我如何在发布更改时强制重新加载客户端?我是否必须告诉浏览器不要缓存我的应用程序(不确定如何在 blazor 上)并在我的应用程序稳定之前承受性能损失?或者有没有办法在第一次 API 调用后使用一些中间件或其他东西强制客户端重新加载?

还是我错过了什么?

可能与我使用 Blazor WebAssembly 3.2.0 Preview 2 中提供的 PWA 模板有关.我仍在从浏览器运行应用程序,但启用 PWA 选项似乎改变了即使将其作为常规网站运行.

解决方案

由于你的应用是PWA,你可以在navigator.serviceWorker对象中声明一个js文件进行注册.此 my.js 文件可以包含 const CACHE_VERSION = 1.0.更新此值应强制客户端下载最新文件.有关详细信息,请参阅 Jeremy Likness 的博文.p>

I have a Blazor app that I'm deploying to Azure for some alpha testing. I've managed to do this and I can run the app from the website just fine.

The problem comes when I make changes to the client and server projects and republish them. Whatever browser is running the client will run whatever is already in the browser cache until the browser history is cleared. That means until the history is cleared the app appears broken because the client requests on the old version don't match the new server API - not to mention my client side changes don't get tested.

How can I force a reload of the client when I publish my changes? Do I have to tell the browser not to cache my app (not sure how on blazor) and take the performance hit until my app stabilizes? Or is there a way to force a client reload after the first API call using some middleware or something?

Or am I missing something?

Edit: It may be relevant that I used the PWA template provided in Blazor WebAssembly 3.2.0 Preview 2. I'm still running the app from a browser, but it seems possible that enabling the PWA option changed the behavior of the app even when running it as a regular website.

解决方案

Since your app is a PWA, you can declare a js file for registration in the navigator.serviceWorker object. This my.js file can contain a const CACHE_VERSION = 1.0. Updating this value should force the client to download the latest files. See Jeremy Likness' blog post for more info.

这篇关于发布更改后强制重新加载 Blazor 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆