public/worker.js
// Function called when the client makes a request
Function called when the client makes a request
Function called when the client makes a request
async function fetchRequest(request) {
  let response = await caches.match(request)
  if (!response) {
    response = await fetch(request)
    const cache = await caches.open(cacheName)
    cache.put(request, response.clone())
  }
  return response
}
async function fetchRequest ( request ) { let response = await caches . match ( request ) if ( ! response ) { response = await fetch ( request ) const cache = await caches . open ( cacheName ) cache . put ( request , response . clone ( ) ) } return response }
Function called when the client makes a request
Function called when the client makes a request
// Check if the requested file is cached // If file isn't cached // Fetch the file // Open our cache // And save the response to the cache // And finally, return our response