Forcing reload of Blazor client after publishing changes
If anyone looks solution for Azure Pipelines and Azure Static Web App deployment, here is what worked for me:
- Added following line on top of service-worker.published.js file.
const CACHE_VERSION = '{#CACHE_VERSION#}'
- Added Bash step to *.yaml file, just change your app location accordingly.
- master
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
submodules: true
- bash: 'sed -i ''s/{#CACHE_VERSION#}/$(Build.BuildId)/'' MathApp/wwwroot/service-worker.published.js'
- task: AzureStaticWebApp@0
inputs:
app_location: 'MathApp'
output_location: 'wwwroot'
azure_static_web_apps_api_token: $(deployment_token)
if you are working on dot net core3.X PWA app, you can add comment in service-worker.published.js so that when browser will compare its cached service worker with updated one, browser will track the changes and load new one.
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.