This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js'; | |
| promyfill('fetch' in window, fetchPolyfill).then((fetch) => { | |
| //fetch is available (polyfill is fetched only if needed) | |
| fetch('users.json'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js'; | |
| const fetchReady = promyfill('fetch' in window, fetchPolyfill); | |
| fetchReady.then(() => { | |
| fetch('users.json'); | |
| }); | |
| //other application logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function run(){ | |
| //other application logic here | |
| const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js'; | |
| const fetchReady = await promyfill('fetch' in window, fetchPolyfill); | |
| fetch('users.json'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class API{ | |
| constructur(){ | |
| //you could do advanced logic to determine the baseUrl | |
| //based on the environment. Or you could simply pass it | |
| //as an argument | |
| this.baseUrl = 'http://laravel.dev/';//keep the slash at the end | |
| } | |
| fetch(url, options){ | |
| return fetch(`${this.baseUrl}${url}`, options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git clone git@github.com:jadjoubran/workbox-tutorial.git | |
| cd workbox-tutorial | |
| npm install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| "globDirectory": "build/", | |
| "globPatterns": [ | |
| "**/*.{css,html,js}" | |
| ], | |
| "swDest": "build/sw.js" | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| if ('serviceWorker' in navigator) { | |
| window.addEventListener('load', () => { | |
| navigator.serviceWorker.register('/sw.js'); | |
| }); | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); | |
| console.log('this is my custom service worker'); | |
| workbox.precaching.precacheAndRoute([]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| "globDirectory": "build/", | |
| "globPatterns": [ | |
| "**/*.{css,html,js}" | |
| ], | |
| "swDest": "build/sw.js", | |
| "swSrc": "src-sw.js" | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); | |
| console.log('this is my custom service worker'); | |
| workbox.precaching.precacheAndRoute([ | |
| { | |
| "url": "css/app.css", | |
| "revision": "fd2e1d3c4c8d43da10afe67a7d69fbd1" | |
| }, | |
| { | |
| "url": "index.html", | |
| "revision": "39b8fb34f8be7ecf969530f1b9e69ba1" |