Return HTML
Build an HTML page inside a function and return it with the correct content-type header, without rendering it on an origin server.
Generate a complete HTML page from a string and return it directly from a function. Use this pattern for lightweight pages, landing screens, or maintenance notices that do not need to be rendered on an origin server.
How it works
The markup is stored in a template literal assigned to the html constant, so the whole page lives inside the function. When the fetch event fires, handleRequest builds a new Response with that string as the body and sets the content-type header to text/html;charset=UTF-8, which tells the browser to render the payload as a web page instead of plain text. event.respondWith() then returns the page to the client, with no request to an origin.
The content-type header is the part that matters most here. Without it, the browser has no instruction to render the body as a page, so keep it set whenever a function returns HTML.