Pan*_*wat 5 blazor blazor-client-side
Blazor 中有缓存清除的解决方案吗?我在 Blazor WebAssembly 中转换了我的 asp.net core 应用程序,我在 razor 页面中使用它asp-append-version=true来进行客户端缓存更新。
发现DLL 存在同样的问题
小智 5
我和我的同事Nurzhan Aitbayev、Yerassyl Shalabayev开发了以下解决方案:
\n"ApplicationSettings": {\n ...\n "Version": "Release-0"\n }\nRun Code Online (Sandbox Code Playgroud)\n"ApplicationSettings": {\n ...\n "Version": "Release-0"\n }\nRun Code Online (Sandbox Code Playgroud)\napp.Use(async (context, next) =>\n {\n context.Response.Headers.Add("Application-Version", Configuration["ApplicationSettings:Version"]);\n await next.Invoke();\n });\nRun Code Online (Sandbox Code Playgroud)\nprivate void CheckAppVersion(HttpResponseMessage response)\n {\n if (response == null)\n {\n throw new ArgumentNullException(nameof(response));\n }\n\n response.Headers.TryGetValues("Application-Version", out var headers);\n if (headers == null || !headers.Any())\n {\n return;\n }\n\n var appVersion = headers.First();\n if (!string.IsNullOrWhiteSpace(appVersion))\n {\n var localVersion = _applicationSettings.Version;\n var isActual = string.Compare(localVersion, appVersion, StringComparison.OrdinalIgnoreCase);\n\n if (isActual != 0)\n {\n throw new OldVersionException("\xd0\x92\xd0\xb5\xd1\x80\xd1\x81\xd0\xb8\xd1\x8f \xd0\xbf\xd1\x80\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x8f \xd0\xbe\xd0\xb1\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb8\xd0\xbb\xd0\xb0\xd1\x81\xd1\x8c");\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\nprotected async Task RefreshPageAsync()\n {\n await JSRuntime.InvokeVoidAsync("reloadPage");\n }\nRun Code Online (Sandbox Code Playgroud)\nJS
\n<script>\n function reloadPage() {\n location.reload(true);\n }\n </script>\nRun Code Online (Sandbox Code Playgroud)\n
根据@Mister Comment添加我的答案。
BlazorPWA.MSBuildnuget包是生成PWA所需的文件。
对于更新缓存,您每次要发布代码时都需要更改 proj 文件。
<ServiceWorkerCacheVersion>1</ServiceWorkerCacheVersion>
<ServiceWorkerForce>true</ServiceWorkerForce>
Run Code Online (Sandbox Code Playgroud)
如果你想实现这个 nuget 包,请检查此项。
| 归档时间: |
|
| 查看次数: |
4935 次 |
| 最近记录: |