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

查看:68
本文介绍了发布更改后强制重新加载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的博客文章.

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天全站免登陆