Skip to content

Instantly share code, notes, and snippets.

@jacky810124
jacky810124 / app.js
Created March 28, 2018 11:25
PWA Day06 Cache On User Interaction
document
.querySelector('.cache-article')
.addEventListener('click', (event) => {
event.preventDefault()
const id = this.dataset.articleId
caches
.open('mysite-article-' + id)
.then((cache) => {
@jacky810124
jacky810124 / sw.js
Created March 22, 2018 15:38
PWA Day05 - fetch event
self.addEventListener('fetch', event => {
console.log('[Service Worker] - fetch event')
event.respondWith(
self
.caches
.match(event.request)
.then(result => {
if (result == null) {
return fetch(event.request)
@jacky810124
jacky810124 / app.js
Created March 22, 2018 15:12
PWA Day05 - register service worker
navigator
.serviceWorker
.register('/sw.js', {
scope: '/app'
})
@jacky810124
jacky810124 / sw.js
Created March 21, 2018 18:07
PWA Day04 cache
const APP_ASSETS_CACHE_NAME = `app-assets-cache-v0.0.1`
self.addEventListener('install', event => {
console.log('[Service Worker] - install event')
event.waitUntil(
self
.caches
.open(APP_ASSETS_CACHE_NAME)
.then(cache => {
@jacky810124
jacky810124 / app-shell.js
Created March 21, 2018 18:01
PWA Day04 app shell
[
'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js',
'https://unpkg.com/[email protected]/dist/vue-router.js',
'https://code.jquery.com/jquery-3.2.1.slim.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js',
'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js',
'/app.js',
'/manifest.json',
'/'
@jacky810124
jacky810124 / app.js
Created March 21, 2018 17:27
PWA Day04 app.js
if ('serviceWorker' in navigator) {
navigator
.serviceWorker
.register('/sw.js')
}
@jacky810124
jacky810124 / index.html
Created March 20, 2018 10:12
PWA Day02 Web Server For Chrome
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#FFFFFF">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
@jacky810124
jacky810124 / index.html
Created March 19, 2018 16:42
PWA Day02 index.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#FFFFFF">
<!-- Manifest JSON File -->
<link rel="manifest" href="/manifest.json">
<!-- Manifest JSON File -->
@jacky810124
jacky810124 / manifest.json
Last active March 19, 2018 16:42
PWA Day02 Manifest
{
"short_name": "order drink",
"name": "好想訂飲料",
"description": "好想訂飲料 - 快找大家訂飲料吧!",
"theme_color": "#FFFFFF",
"background_color": "#FFFFFF",
"display": "standalone",
"orientation": "portrait",
"icons": [
{
array = (new Array(5000)).fill(1)
task = array.map(item => {
return fetch('http://localhost:5000/diandian-landing-payment/us-central1/api/test')
})
duplicated = []
Promise
.all(task)
.then(result => result.map(item => item.json()))