Skip to content

Instantly share code, notes, and snippets.

@jacky810124
Created March 28, 2018 11:25
Show Gist options
  • Select an option

  • Save jacky810124/570b4d74ae40116f18e4ea17074fc8fd to your computer and use it in GitHub Desktop.

Select an option

Save jacky810124/570b4d74ae40116f18e4ea17074fc8fd to your computer and use it in GitHub Desktop.
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) => {
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