Static page in Workers?

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>

1 Like

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'
    }
  })
}
5 Likes