Blazor PWA
With the Web Assembly 3.2.0 Preview 3 release of the Blazor
Web Assembly template you can now make a Progressive Web Application (PWA). This can only be done with the web assembly
because of the requirements for a PWA.
Before we can talk about the Blazor PWA, we need to make sure we understand what a PWA is.
Via Wikipedia:
“A progressive web application is a type of application software delivered through the web, built using common web technologies including HTML, CSS and JavaScript. It is intended to work on any platform that uses a standards-compliant browser.”
The key takeaway from the definition is the “works on any platform”. Don’t just mobile, but Windows, Mac and even Chrome Book.
PWAs is not a new technology, it is just HTML, JS and CSS. It is the packaging of these that make it a PWA.
Why build a PWA
Like most decision in development, the answer depends. Sometimes this answer can be decided for non-technical
reasons, Marketing, Branding etc. But
from the development side of the decision, there are a lot of factors that go
into the choice:
1.
You need a way to quickly get an application to
user and can’t wait to go through the app stores
2.
You have multiple platforms to support and your
skill set is not in the native platforms
3.
You don’t want to give Apple 30% of your revenue
4.
You don’t need low level hardware access
Key Components
There are 3 core components that qualify an application to be considered a PWA:
1. Secure Communication
a. Must communication via HTTPS
2. Service Worker
a. A javascirpt script that allows intercepting and control of how a web browser handles its network requests and asset caching.
b. Creates reliably fast web pages
c. Provides offline experiences.
3. Manifest file
a. Json formatted Meta Data about your application
b. Controls how your app appears to the user
1. Secure Communication
a. Must communication via HTTPS
2. Service Worker
a. A javascirpt script that allows intercepting and control of how a web browser handles its network requests and asset caching.
b. Creates reliably fast web pages
c. Provides offline experiences.
3. Manifest file
a. Json formatted Meta Data about your application
b. Controls how your app appears to the user
That is all that it takes to make any web application a PWA.
There are a ton of resources to help create the service
worker and the manifest file. See the end
of the post for a list of those resources.
Blazor PWA Template
When you select the PWA check box on the create project
selection, it will create the normal Web Assembly project but with the manifest
file and the service worker script and will add those to the application.
Manifest File
Here is what is in the manifest file:
{
"name":
"MyNewProject",
"short_name": "MyNewProject",
"start_url": "./",
"display":
"standalone",
"background_color": "#ffffff",
"theme_color": "#03173d",
"icons": [
{
"src":
"icon-512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}
You do have to have icons listed for each platform for best
results.
As you can see, it will only provide the bare minimum of the
meta data you can have. Listed in the
resource below, there is a web site that will help you create the manifest file
and help you create the FAVIcons for each platform.
Special note for Apple.
They have their own set of meta tags to use in order for the values to
be seen properly on iOS.
Service Worker
The service worker is executed in a separate thread and is responsible
for acting as a proxy for the web server.
It will intercept web request and allow you to do anything you need to
do. Such as pull from cache first, or
from the server and even reroute if needed.
Here is the service worker script that the Blazor template uses:
self.addEventListener('fetch', () => { });
That’s it. Not much to it. You can add all the functionality you may
need to handle your application’s need.
As you can see there is not much to making any web
application into a PWA. When you use a
PWA and when to go native is always a hard question. There are times you have go native, but with
the additional advantages that the PWA can give you, it is a now a little
harder decision. But with the PWA you at
least now have a new tool to put in your toolbox.
Additional Resources
3.
Intro to PWA
Comments
Post a Comment