by Gerard Sans | @gerardsans
SANS
GERARD
Spoken at 151 events in 37 countries
Reliable
Storage
Native-like Features
Great User Experience
Offline
Ready
Native
Applications
PWA
Applications
Web/SPA
Applications
Reach
Capabilities
Web App
Manifest
Service
Worker
Security
(HTTPS)
index.html
Cache
Hosting
Service
Worker
app.js
app.js
app.js
logo.png
logo.png
logo.png
app.js
logo.png
app.js
logo.png
index.html
Cache
Hosting
Service
Worker
OFFLINE
app.js
logo.png
app.js
logo.png
app.js
logo.png
app.js
logo.png
🦄
🌩️
Update
Init
Add
Push
interactions
storage
notifications
auth
analytics
function
api
hosting
xr
transcribe
translate
polly
rekognition
comprehend
AppSync
GraphQL
$ amplify init
$ amplify add auth
$ amplify add api
$ amplify push
src/app.component.ts
type Chatty @model {
id: ID!
user: String!
message: String!
createdAt: AWSDateTime
}
src/app.component.ts
import { DataStore } from "@aws-amplify/datastore";
import { Chatty } from "./models";
await DataStore.save(new Chatty({
user: "gsans",
message: "Hi everyone!👋",
createdAt: new Date().toISOString()
}))
src/app.component.ts
import { DataStore, Predicates } from "@aws-amplify/datastore";
import { Chatty } from "./models";
const msg = await DataStore.query(Chatty, Predicates.ALL);
src/app.component.ts
$ vue add @vue/pwa
src/main.js (Updated)
> + import './registerServiceWorker'
src/registerServiceWorker.js (Added)
src/app.component.ts
$ yarn build
src/app.component.ts
└── dist
├── css
│ └── app.<version>.css
├── img/icons
│ ├── android-chrome-<size>.png
│ └── ...
├── js
│ ├── app.<version>.png
│ └── ...
├── favicon.ico
├── index.html
├── manifest.json
├── precache-manifest.<version>.json
├── robots.txt
└── service-worker.js
$ cd dist
/dist$ python -m SimpleHTTPServer 8887
// vue.config.js
const manifest = require('./public/manifest.json')
module.exports = {
pwa: {
name: manifest.short_name,
themeColor: manifest.theme_color,
msTileColor: manifest.background_color,
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: 'src/service-worker.js',
}
src/app.component.ts
// src/service-worker.js
workbox.core.setCacheNameDetails({ prefix: 'amplify-datastore' })
workbox.core.skipWaiting()
workbox.core.clientsClaim()
const cacheFiles = [{
"revision": "e653ab4d124bf16b5232",
"url": "https://aws-amplify.github.io/img/amplify.svg"
}]
self.__precacheManifest = cacheFiles.concat(self.__precacheManifest || [])
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
src/app.component.ts
// <div v-if="offline">You are offline.</div>
// App.vue
import { Hub } from 'aws-amplify';
export default {
data() {
return { offline: undefined };
},
created() {
this.listener = Hub.listen('datastore', {payload:{event}} => {
if (event === 'networkStatus') {
this.offline = !data.active;
}
})
}
}
src/app.component.ts