Marko + Cloudflare Workers

See the the cloudflare sample project for a working example.


When using Marko with Cloudflare Workers, make sure that Marko is loaded with a worker export condition. Most bundlers support defining export conditions.

After that point, imported .marko files will export a .stream method that returns a worker compatible ReadableStream. You can then respond with that returned stream:

import Template from "./index.marko";

addEventListener("fetch", (event) => {

async function handleRequest(request) {
  return new Response(, {
    headers: {
      status: 200,
      headers: { "content-type": "text/html;charset=UTF-8" },

BYOB (Bring your own bundler)

For the large portion of Marko's API a bundler is required. The example code above assumes that Marko templates can be loaded in your environment. Marko supports a number of bundlers, take a look through our supported bundlers and pick what works best for you.

EDIT on GitHub


Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.

Chat in Marko's Discord Server