Created
March 28, 2018 11:25
-
-
Save jacky810124/570b4d74ae40116f18e4ea17074fc8fd to your computer and use it in GitHub Desktop.
PWA Day06 Cache On User Interaction
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
| document | |
| .querySelector('.cache-article') | |
| .addEventListener('click', (event) => { | |
| event.preventDefault() | |
| const id = this.dataset.articleId | |
| caches | |
| .open('mysite-article-' + id) | |
| .then((cache) => { | |
| fetch('/get-article-urls?id=' + id) | |
| .then((response) => { | |
| // /get-article-urls returns a JSON-encoded array of | |
| // resource URLs that a given article depends on | |
| return response.json() | |
| }) | |
| .then((urls) => { | |
| cache.addAll(urls) | |
| }) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment