Skip to content

Consider adding Progressive Web App (PWA) option to the Blazor Web App template #48935

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

Open
danroth27 opened this issue Jun 21, 2023 · 19 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-templates Pillar: New Blazor Priority:1 Work that is critical for the release, but we could probably ship without triaged
Milestone

Comments

@danroth27
Copy link
Member

Currently we only support the Progressive Web App (PWA) template option with the Blazor WebAssembly template. This is primarily because offline scenarios don't make sense with Blazor Server. That said, it's still valid to have an installable PWA that doesn't support offline execution. Could we make our PWA support more general?

With the current Blazor Web App template it's not clear to me if it would ever make sense to enable offline support. The one case this might make sense is if we end up with some option or combination of options that make the entire app interactive using the WebAssembly or Auto render modes, but this isn't the currently plan.

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Jun 21, 2023
@javiercn
Copy link
Member

@danroth27 that requires us to move the service-worker support down one layer to static web assets, which we punted.

It should be doable though.

@mkArtakMSFT mkArtakMSFT added this to the .NET 9 Planning milestone Jun 21, 2023
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Jun 21, 2023
@mkArtakMSFT
Copy link
Contributor

Depends on #46999

@veertien
Copy link

With the current Blazor Web App template it's not clear to me if it would ever make sense to enable offline support

Please consider this scenario: A Blazor WebAssembly PWA with offline support and server prerendering.

I have it working in .NET 7 but it is quite a head ache to migrate to .NET 8.

@RyansBello
Copy link

I want to kick off a new project with .NET 8, hoping it kicks off or starts off like Blazor .NET 7 with its awesome Hosted option, which already includes the fantastic PWA capability.
With .NET 8, I can have a framework almost the same as the project setup:

Interactive render mode => WebAssembly
Interactivity location => Global

Unfortunately, that amazing PWA feature is missing from .NET 8. How can we build an extraordinary and user-friendly web framework as promised when that feature is gone?

Please reconsider bringing back the PWA capability in the Blazor Server App feature. Perhaps by restricting the PWA options to appear only if the settings are configured, as suggested by @SteveSandersonMS in #50433

@SteveSandersonMS
Copy link
Member

@RyansBello You can still build a PWA; we just don't have checkbox in the template wizard that sets it up for you. For example you can add your own service-worker.js file to the project (e.g., starting with the one from the WebAssembly Standalone PWA template) and corresponding <ServiceWorkerAssetsManifest> and <ServiceWorker> entries in your .csproj.

I totally appreciate it's nonobvious and harder to get started than if there was a template option. I agree it would be good if we could add a template option for it in the future. If you are determined, it is possible to proceed right now with some extra manual setup work.

@MarkSky
Copy link

MarkSky commented Nov 24, 2023

In .Net 7, Blazor Webassembly with Asp.Net Core hosting could prerender and also work on PWA, just like the JavaScript Framework.
But in .Net 8, it doesn't support both PWA and prerender on the same web project, if I want to use prerender in Blazor, I have to use Blazor Web App.
So I thing adding PWA option to the Blazor Web App is needed.

@ghost
Copy link

ghost commented Dec 22, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS
Copy link
Member

Based on some community feedback, I tried out setting up a PWA manually using a combination of the Blazor Web and Standalone Blazor WebAssembly templates: https://github.com/SteveSandersonMS/MyDotNet8PWA

It does work in this simple case. However:

  • It's very nontrivial to set up. You have to make lots of nonobvious changes to CSS file paths and inside service-worker.published.js to make it work. Unless you're very familiar with the framework it's likely you'd be fighting problems for a long time.
  • It still doesn't generalize to more complex app patterns. For example, if you wanted a subset of pages still to be SSR, how would you do it? You need to have an interactive router for the PWA to work, but you need to not have an interactive router to be able to reach the SSR page.
    • I thought I could work around it by using MapWhen in the host Program.cs to use different root components for different URL subsets, but that didn't work, because if you have multiple calls to MapRazorPages then they register clashing endpoints for _framework/blazor.web.js. It doesn't look like there's any sensible way to host more than one Blazor Web application in a single app right now.

@mkArtakMSFT mkArtakMSFT added the Priority:1 Work that is critical for the release, but we could probably ship without label Jan 4, 2024
@laryhil
Copy link

laryhil commented Jan 22, 2024

we need blazor wasm with server prerender with pwa.... please @danroth27 and @SteveSandersonMS just bring it back asap...

@danroth27 danroth27 changed the title Consider adding Progressive Web App option to the Blazor Web App template Consider adding Progressive Web App (PWA) option to the Blazor Web App template Jan 26, 2024
@alex-fitplans
Copy link

I would love to have PWA support with blazor auto render mode.
It would allow fast initial load for new customers AND the option to install the app for existing customers.

In fact, the scenario you mention @SteveSandersonMS is the perfect scenario for me: Have SSR for the landing/static pages, and have interactive PWA with auto render mode for the app portion of the website. At the moment I work around that with two websites, which works but isn't ideal from a customer journey perspective.

I had a look at your example (thanks!), reading your warnings I guess it's best to not use this on production?

@gragra33
Copy link

gragra33 commented Apr 1, 2024

@danroth27 @SteveSandersonMS I'm just giving this a ping to see if it made it onto the roadmap for .Net 9.0. I am like others, would love to migrate from .Net 7.0.

@danroth27
Copy link
Member Author

I'm just giving this a ping to see if it made it onto the roadmap for .Net 9.0. I am like others, would love to migrate from .Net 7.0.

@gragra33 Unfortunately, this issue didn't make the cut for .NET 9, but you should still be able to retarget your existing app to .NET 8 without having to make any code changes. The existing Blazor Server and Blazor WebAssembly hosting models are still fully supported in .NET 8.

@gragra33
Copy link

gragra33 commented Apr 2, 2024

@danroth27 Thanks for responding so quickly. I will continue to work with what is available. I will hold hope for .Net 10. Auto + PWA would be powerful.

@douglassimaodev
Copy link

Even if we dont want to work off-line, the app can be fully online but I just would like to give to my user the experience of having something "native/installed" to his desktop or mobile instead keep opening the browser and searching for the website/app
any update on that query?

@SteveSandersonMS
Copy link
Member

@douglassimaodev If all you want to do is prompt the user to add your page to their homescreen, you can easily add that to your site following the guide at https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable. This isn't a Blazor-specific thing - it works the same with any web app.

@hgirma
Copy link

hgirma commented Apr 15, 2024

@douglassimaodev Once installed, how do you upgrade it when a new version of the app is available?

@Laftek
Copy link

Laftek commented May 29, 2024

This is must feature to have to make it easier for us

@sdktraceur
Copy link

And we use PWA to get full screen on the Android devices, it's killer feature.

@PSCourtney
Copy link

@douglassimaodev Once installed, how do you upgrade it when a new version of the app is available?

My approach is to store a version number in my db, and have a check on page layout level to check the version with an api call. If there is a mismatch prompt the user to update.

Or handle it on the service-worker.js level https://whuysentruit.medium.com/blazor-wasm-pwa-adding-a-new-update-available-notification-d9f65c4ad13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-templates Pillar: New Blazor Priority:1 Work that is critical for the release, but we could probably ship without triaged
Projects
None yet
Development

No branches or pull requests