Static page in Workers?


#1

How would one use Workers to server static HTML without hitting the origin server?

I’d really appreciate a sample script with a placeholder for <html>EVERYTHING</html>


#2

Sure thing, try this:

addEventListener('fetch', event => {
  event.respondWith(fetchAndLog(event.request))
})

async function fetchAndLog(request) {
  return new Response("<html>EVERYTHING</html>", {
    headers: {
      'Content-Type': 'text/html'
    }
  })
}