Skip to content

Instantly share code, notes, and snippets.

View webmaxru's full-sized avatar
😀
Progressive Web Max

Maxim Salnikov webmaxru

😀
Progressive Web Max
View GitHub Profile
@webmaxru
webmaxru / app.js
Created February 27, 2019 19:10
Workbox 4: workbox-window. Adding BroadcastChannel
const updateChannel = new BroadcastChannel('precache-channel');
updateChannel.addEventListener('message', event => {
if (confirm(`New content is available!. Click OK to refresh`)) {
window.location.reload();
}
});
@webmaxru
webmaxru / service-worker.js
Created February 27, 2019 19:07
Workbox 4: workbox-window. Adding broadcastUpdate plugin
workbox.precaching.addPlugins([
new workbox.broadcastUpdate.Plugin('precache-channel')
])
@webmaxru
webmaxru / service-worker.js
Last active November 29, 2018 20:53
Background Fetch. Step 4: Extra useful handlers
addEventListener('backgroundfetchfail', event => {
console.log('[Service Worker]: Background Fetch Fail', event.registration);
event.waitUntil(
(async function() {
try {
const cache = await caches.open(event.registration.id);
const records = await event.registration.matchAll();
const promises = records.map(async record => {
const response = await record.responseReady
if (response && response.ok) {
@webmaxru
webmaxru / index.html
Last active November 29, 2018 17:27
Background Fetch. Step 3: Improving UX
<button id="bgFetchButton">Store assets locally</button>
<div id="progressStatus">Progress: waiting...</div>
<script>
bgFetchButton = document.querySelector('#bgFetchButton');
progressStatus = document.querySelector('#progressStatus');
bgFetchButton.addEventListener('click', async event => {
// Let's assume that we got some unique ID of the asset set we want to download
let assetToFetchId = 'series';
@webmaxru
webmaxru / index.html
Last active November 29, 2018 16:52
Background Fetch. Step 2: Storing the data received
<script>
bgFetchButton.addEventListener('click', async event => {
try {
event.target.disabled = true;
const registration = await navigator.serviceWorker.ready;
registration.backgroundFetch.fetch('my-fetch', [
'/assets/s01e01.mpg',
'/assets/s01e02.mpg'
$ http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8084
http://172.16.110.136:8084
@webmaxru
webmaxru / index.html
Last active November 29, 2018 16:53
Background Fetch. Step 1: Doing something...
<button id="bgFetchButton">Store assets locally</button>
<script>
bgFetchButton = document.querySelector('#bgFetchButton');
bgFetchButton.addEventListener('click', async event => {
try {
const registration = await navigator.serviceWorker.ready;
registration.backgroundFetch.fetch('my-fetch', ['/assets/s01e01.mpg']);
} catch (err) {
console.error(err);
@webmaxru
webmaxru / service-worker.js
Created October 30, 2018 22:23
Minimal service worker for Add To Home Screen
addEventListener('fetch', event => {
// Do nothing
});
@webmaxru
webmaxru / GoogleForms-to-Trello.gs
Last active July 6, 2018 10:30 — forked from jhannes/GoogleForms-to-Trello.gs
Google Forms to Trello
var authentication = "key=...&token=...";
var idBoard = "...";
var inboxList = "...";
var updatedLabel = "...";
var travelLabel = "...";
// To process all current records - run sendAll()
// To set up a trigger for the new records - run init()
function init() {
@webmaxru
webmaxru / control-broadcast.component.ts
Created November 4, 2017 15:48
checkForUpdate and activateUpdate methods of SwUpdate
checkForUpdate() {
console.log('[App] checkForUpdate started')
this.swUpdate.checkForUpdate()
.then(() => {
console.log('[App] checkForUpdate completed')
})
.catch(err => {
console.error(err);
})
}