-
Notifications
You must be signed in to change notification settings - Fork 232
PWA Configuration
In this section of the tutorial we'll discuss what's involved in a PWA...
There's lots of information available on the Web about PWA's so I won't try to duplicate that here. Here's some of the links you can take a look at:
In summary, a PWA is an app that can easily be added to the homescreen and used without a browser bar. PWA's can also be tuned to do more offline. The app feels and acts more like a Native app.
The Manifest file is used to configure your PWA (not to be confused with your Webpack Chunk Manifest file). The file gets copied from your static
folder (and also the icons in static/img/
):
static/manifest.json
{
"name": "vue-pizza",
"short_name": "Vue Pizza",
"icons": [
{
"src": "/app/static/img/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/app/static/img/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "/app/index.html",
"display": "standalone",
"background_color": "#000000",
"theme_color": "#4DBA87"
}
The Service Worker allows for offline mode and is generated by the Webpack plugin:
build/webpack.prod.conf.js
// ...
plugins: [
// ...
// service worker caching
new SWPrecacheWebpackPlugin({
cacheId: 'vue-pizza', // <-- Update this id for your app.
filename: 'service-worker.js',
staticFileGlobs: ['dist/**/*.{js,html,css}'],
minify: true,
stripPrefix: 'dist/'
})
After you npm run build
for production you'll see it appear in your /dist
folder.
The proper view port (so that both desktop and mobile devices scale correctly) has been set via a meta tag in index.html
.
index.html
<meta name="viewport" content="width=device-width, initial-scale=1">
To take full advantage of a PWA (so that mobile devices will correctly consider your app a PWA and service works can work) you will need to serve your app over HTTPS.
You can read how to set up SSL on your localhost nginx server here: https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-16-04.
Github pages now offers HTTPS. You can read more here: https://blog.github.com/2018-05-01-github-pages-custom-domains-https/
CloudFlare offers free HTTPS. Here are the steps you'll need to take:
- Make sure you setup your github.io (ie.
prograhammer.github.io
) to allow for your domain name (ie.prograhammer.com
). You'll go to settings in your github.io repo and add www.your-domain.com (ie.www.prograhammer.com
) there. You'll also need to add a file namedCNAME
that contains www.your-domain.com (ie.www.prograhammer.com
). - Sign up for free CloudFlare account for www.your-domain.com
- Go to CloudFlare's DNS tab:
- Copy CloudFlare's nameservers and go to your registrar (where you purchased your-custom-domain) and add them there so your registrar will now point to CloudFlare's NameServers to resolve.
- Add a flat CNAME rule, for example:
CNAME * prograhammer.github.io
- Make sure you have turned on SSL. See the section "Domain Summary" in the Overview tab. Make sure you have it set for
full
. - Go to CloudFlare's Page Rules tab and add the rule
http://*.your-domain.com/*
with settings asAlways Use HTTPS
. - Wait for a few hours (up to 24) and then Github should pick it up and it should work.
- Turn off CloudFlare caching temporarily by turning on "Dev" mode so you can see changes immediately reflected online.
You can read about install banners and "Add to Home Screen" here (includes notes on "testing" for them as well): https://developers.google.com/web/fundamentals/engage-and-retain/app-install-banners/
Basically, it's just a popup indication from the mobile device that allows users to more easily add your app to their homescreen (allows for shortcut and opens without a browser bar). The restrictions are:
- Has a web app manifest file with:
- a short_name (used on the home screen)
- a name (used in the banner)
- a 144x144 png icon (the icon declarations must include a mime type of image/png)
- a start_url that loads
- Has a service worker registered on your site.
- Is served over HTTPS (a requirement for using service worker).
- Is visited at least twice, with at least five minutes between visits.