Saturday, May 18, 2019

I saw Avindra Fernando speak at the Norwegian Developers Conference nine days ago on service workers for progressive web applications.

Upfront, we were walked through a five step history to get to the PWA. First, native apps require a very specific skillset and really two specific skillsets if you are to build for both iOS and Android and make that three if you go back in time a few years to when people took the Windows Phone seriously. What you build for one platform will not transfer easily to another. Second, hybrid apps appeared. These shipped through the various "play stores" such as the Apple Store in the iPhone space and were a hodgepodge between native apps and what we may think of as "Mobile Web" (which is coming up two steps from now) looping in things like Cordova to have at the pictures on your phone. Third, cross-platform native apps emerged. Xamarin can solve all of our problems, right? No, it can't. Fourth, mobile web, reactive web sites that used CSS media queries to just fall over from the regular desktop version of a web site to a web site on your phone came to be. Unlike hybrid apps these did not involve a trip to a store. They were just web sites that you reached through the browser on your phone, sidestepping all that extra drama. Fifth, progressive web apps come and they are applications which are mobile webesque yet mobile-like. They have three traits: never down as they have offline content to compensate for a lack of a connection, giving illusions of speedy content to deal with slow connections, and engaging! The installation progress speaks to the engaging ideal. You just go to a URL at your browser at your phone to get a service worker that will install your PWA. Again, no store! Steve Jobs is dead. He can't control what you see and what you do anymore. You're free. Service workers need to run over https. A lot of your traffic will be exposed to a service worker, so if someone intercepts that in a man-in-the-middle attack that would be bad. The manifest.json file is sort of like the appsettings.json or web.config file in a progressive web application. Another cornerstone file is service-worker.js and there is going to be something like registerServiceWorker.js to register the service worker, but maybe with a different name depending on your architecture. Vue was used in the example code shown and in main.js there was code to import the service worker. Service workers send and receive push notifications and all of the major browsers are on board with service workers. The display option in manifest.json has four possibilities which are fullscreen, standalone, minimal-ui, and browser and which are discussed here. In short, the standalone option, which will give the appearance of a native web app, was recommended. Lighthouse will help you convert your application to a PWA. You can only have one service worker running at a time so if you have two browser tabs open to two places trying to do service workers at your laptop the second service worker is going to stop the first. .skipWaiting() is used to do this. It may take a couple of tries to install a service worker as suggested here:

Since writing of the Norwegian Developers Conference last, my copy of "Fullstack React: The Complete Guide to Reactjs and Friends" as mentioned here failed to arrive as Amazon shipped it to an old address for me in Austin, Texas. I guess I'll stick to Angular, huh? While I am referencing the old blog posting I might as well mention that the guy with the mohawk is Josh Sheppard. And... since I namedropped Amazon... Avindra Fernando mentioned that Flipkart, the Amazon of India, has converted its web presence to a PWA.

No comments:

Post a Comment