-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to clear application cache and then refresh to see the new changes on PWA enabled Blazor WebAssembly apps #18
Comments
This behavior is by design on the You should close all browser instances after a new version of your Blazor Wasm PWA was fetched in the background to see a new version's contents. The official documentation is here: P.S. |
I'm trying to debug by logging Do we need to try something like below? const request = shouldServeIndexHtml
? (new URL(event.request.url)).pathname === '' ? 'index.html' : (new URL(event.request.url)).pathname.replace(/\/$/, '') + '/index.html'
: event.request; This way index.html will forced to reload? Please correct me if I'm wrong. |
@fingers10
The above behavior is definitely no wonder. Please remember that service worker processes are like a proxy server inside a web browser. It is a process like a proxy, so it is obvious that a service worker intercepts all HTTP requests, such as static assets.
The answer is no. What you consider to try is not make sense. Because the JavaScript code which you are going to modify is the part of responding to an HTTP GET request with a fallback page (like a However, don't try to modify the code around There is a deep reason why the service worker and its offline cache will never update until all browser tabs that open it are closed. I can t explain it now because there is not enough time to do that, but the keyword is "atomic". If you break this offline strategy by changing the above code, you and your site users will see confused site content mixed up with new and old versions. All we can do to update your PWA site as soon as a newer version is detected is the following strategy. "Notify a new version is available for site users via a user interface such as snack bar, and reload the page by user's action such as clicking the "update now" button you provided as UI elements." I'll explain how to implement the above strategy as a specific code, but please give me a few more days or a week. The PoC sample code is almost done on my hand. I have to spend time validating and refining that sample code. |
I implemented a sample code. Step.1 Copy the files in the "BlazorPWA2.zip" below into your Blazor WebAssembly project.
Step.2 Add the Step.3 Change your ...
<!--
Remove the line "<script>navigator.serviceWorker.register('service-worker.js');</script>",
and insert the line below instead.
-->
<script src="blazor-pwa-updater.js" data-script-path="service-worker.js"></script>
</body>
... Step.4 Add one line below to the top of your self.addEventListener('message', event => { if (event.data?.type === 'SKIP_WAITING') self.skipWaiting() });
... Then you can get the behavior like the following animation GIF picture. Would you try to apply these changes to your app? P.S. |
@jsakamoto can we connect and work together on this? I would like to learn and understand a lot from you. I would like to learn on how you think when solving these problem. The way you approach the solution. This could open the doors for me to think in new ways or get myself exposed to new learning |
@jsakamoto , I tried the above steps with sample pwa app and published to https://fingers10.github.io/WasmServerPrerender/ but I'm not able to see the changes and update button. New changes are visible only when I press Steps I tried:
Please can you assist? |
@fingers10
Do you remember that the PWA won't be updated to the new version without closing all browser windows by default? Can you understand? |
I tried closing and opening browser window with the same repo. But not working for me. Steps I tried,
Every time I closed and opened the chrome browser. I also installed the site as PWA. When I close the PWA and open I didn't see yes button but the contents are updated. PWA.Not.Reloading.Issue.mp4 |
@fingers10 And I clicked the "Yes" button, then the page was reloaded, and the page was settled. Everything looks well work for me for now. If your browser still shows no-changes contents "Welcome to your new app" message, could you take a screenshot of your browser's developer tools window like below? (The "Application" Tab > "Service Workers" section) |
@jsakamoto Yeah I also noticed the update message. Looks like issue is sporadic. I'll do another round of testing to make sure if something else is wrong. |
@fingers10 Another one is the "The new version is ready" indicator will be shown only when after all updated contents are downloaded correctly in background. It was not when a browser detected the new version. The above factors mean sometimes it will take much longer than our expectation until the "The new version is ready" indicator has appeared. I hope these knowledges are helpful for you. |
@jsakamoto I have a suggestion if this is going to be published as nuget package. Can we supply a custom UI to refresh and get new content instead of default one? |
Yes. I'll provide the ability on the NuGet package library I'm going to publish to customize UI fully. |
@fingers10 |
From: @fingers10
(The original post is in the Issue #17)
@jsakamoto The fix provided in the
service-worker.published.js
,Change the code inside the
onFetch()
function fromconst request = shouldServeIndexHtml ? 'index.html' : event.request;
toconst request = shouldServeIndexHtml ? (new URL(event.request.url)).pathname.replace(/\/$/, '') + '/index.html' : event.request;.
creates a cache issue.
Steps:
Index.razor
screen.index
url of the app.Video showing the problem:
Index.razor
by adding<h1 style="background-color:yellow">Hello, Cache Problem</h1>
.index
url of the app.CacheProblem.mp4
The text was updated successfully, but these errors were encountered: