Accept header on incoming requests, you can serve a lean Markdown version of your pages to LLMs while humans continue to see normal HTML.
This technique was inspired by a post from the Bun team on X and is now live on skeptrune.com. You can verify it right now:
Static site generators are already halfway there
Static site generators like Astro and Gatsby already generate a big folder of HTML files, typically in adist or public folder through npm run build. The only missing piece is converting those HTML files to Markdown.
There’s a great CLI tool for this: html-to-markdown. Install it as a dev dependency:
dist/html to Markdown files in dist/markdown, preserving the directory structure:
package.json as a post-build action:
Moving all HTML files to
dist/html first is only necessary if you’re using Cloudflare Workers, which will serve existing static assets before falling back to your Worker. If you’re using a traditional reverse proxy, skip that step and convert directly from dist to dist/markdown.After finishing this setup, there’s a simpler Cloudflare-specific alternative: add
run_worker_first = ["*"] to your wrangler.json. This forces the worker to always run first, so you don’t have to move files around at all.Cloudflare Workers configuration
If you’re hosting on Cloudflare Workers, configuring this requires more steps than a traditional reverse proxy. If you’re using Nginx or Caddy, skip this section — you’ll have an easier time. Cloudflare Workers force you into a different paradigm. What would normally be a simple Nginx rewrite rule becomes customwrangler.jsonc configuration, shadow directories, and JavaScript that manually checks headers and uses env.ASSETS.fetch to serve files.
This is also what makes Next.js middleware click: it’s not middleware in the REST API sense. It’s more like “use this where you would normally have a real reverse proxy.” Both Cloudflare Workers and Next.js Middleware are JavaScript-based reverse proxies that intercept requests before they hit your application.
wrangler.jsonc
Reference a new worker script and bind your build output directory as a static asset namespace:Worker script
Below is a minimal worker that inspects theAccept header and serves Markdown when requested, otherwise falling back to HTML:
Caddy configuration
If you’re using a traditional reverse proxy, Caddy makes this significantly simpler. Here’s a completeCaddyfile configuration: