From 2fb0a52894bee169ce081fbc8752152d8d668ed8 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 26 Jan 2019 11:07:17 -0800 Subject: [PATCH] blog: add progressive webapp conversion post --- ...rogressive-webapp-conversion-2019-01-26.md | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 blog/progressive-webapp-conversion-2019-01-26.md diff --git a/blog/progressive-webapp-conversion-2019-01-26.md b/blog/progressive-webapp-conversion-2019-01-26.md new file mode 100644 index 0000000..d21255b --- /dev/null +++ b/blog/progressive-webapp-conversion-2019-01-26.md @@ -0,0 +1,194 @@ +--- +title: How To Make a Progressive Web App Out Of Your Existing Website +date: 2019-01-26 +also_for: "Heroku's blog (TODO: put link here)" +thanks: Nathanial, Andrew Konoff +--- + +# How To Make a Progressive Web App Out Of Your Existing Website + +[Progressive web apps](https://developer.mozilla.org/en-US/docs/Web/Apps/Progressive) enable websites to trade some flexibility to function more like native apps, without all the overhead of app store approvals and tons of platform-specific native code. Progressive web apps allow users to install them to their home screen and launch them into their own pseudo-app frame. However, that frame is locked down and restricted, and only allows access to pages that are subpaths of the scope of the progressive web app. They also have to be served over HTTPS. Updates to these can be deployed without needing to wait for app store approval. + +The core of progressive web apps are [service workers](https://developers.google.com/web/fundamentals/primers/service-workers/), which are effectively client-side Javascript daemons. Service workers can listen for a few kinds of events and react to them. One of the most commonly supported events is the [fetch event](https://jakearchibald.github.io/isserviceworkerready/#fetch-event); this can be used to cache web content offline as explained below. + +There are a large number of web apps that fit just fine within these [rules and restrictions](https://developer.mozilla.org/en-US/docs/Web/Apps/Progressive/App_structure), however there could potentially be compatibility issues with existing code. Service worker updates will be pushed out [with respect to standard HTTP caching responses](https://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours). Plus, you get to use plenty of native APIs, including geolocation, camera, and sensor APIs that only native mobile apps used to be able to take advantage of. + +In this post, we’ll show you how to convert your existing website into a progressive web app. It’s fairly simple, only really requiring the following steps: + +* Creating an app manifest +* Adding it to your base HTML template +* Creating the [service worker](https://developers.google.com/web/fundamentals/primers/service-workers/) + * Serving the service worker on the root of the scope you used in the manifest +* Adding a +``` + +And then deploy these changes – you should see your service worker posting logs in your browser’s console. If you are testing this from a phone, see platform-specific instructions [here for iOS+Safari](https://www.dummies.com/web-design-development/how-to-use-developer-tools-in-safari-on-ios/) and [here for Chrome+Android](https://developers.google.com/web/tools/chrome-devtools/remote-debugging/?hl=en). + +## Deploying + +Deploying your web app is going to be specific to how your app is developed. If you don't have a place to put it already, [Heroku](https://heroku.com) offers a nice and simple way to host progressive web apps. Using [the static buildpack](https://github.com/heroku/heroku-buildpack-static) is the fastest way to deploy a static application already built to Javascript and HTML. You can look at [my fork of GraphvizOnline](https://github.com/Xe/GraphvizOnline) for an example of a Heroku-compatible progressive web app. Note that if you deploy this, you will need to edit the start URL in [the manifest](https://github.com/Xe/GraphvizOnline/blob/master/manifest.json#L8) to the URL that will reach the deployed website – for instance, `sandy-beach-3033.herokuapp.com`. + +## Using Your Progressive Web App + +For iOS Safari, go to the webpage you want to add as an app, then click the share button (you may have to tap the bottom of the screen to get the share button to show up on an iPhone). Scroll the bottom part of the share sheet over to "Add to Home Screen.” The resulting dialog will let you name and change the URL starting page of the progressive web app before it gets added to the home screen. Users can then launch, manage and delete it like any other app, with no effect on any other apps on the device. + +For Android with Chrome, tap on the hamburger menu in the upper right hand corner of the browser window and then tap "Add to Home screen.” This may prompt you for confirmation, then it will put the icon on your homescreen and you can launch, multitask or delete it like any other app. Unlike iOS, you cannot edit the starting URL or name of a progressive web app with Android. + +After all of these steps, you will have a progressive web app. Any page or asset that the users of that progressive web app (or any browser that supports service workers) loads will seamlessly be cached for future offline access. It will be exciting to see how service workers develop in the future. I'm personally excited the most for [background sync](https://developers.google.com/web/updates/2015/12/background-sync) – I feel it could enable some fascinatingly robust experiences. +