Skip to content

perf(webapp): run the proxy only on post requests it acts on - #7556

Merged
idoshamun merged 1 commit into
mainfrom
webapp-proxy-matcher
Dec 3, 2026
Merged

idoshamun merged 1 commit into
mainfrom
webapp-proxy-matcher

Conversation

@idoshamun

@idoshamun idoshamun commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Requested by Ido · project thread

Changes

  • The proxy (proxy.ts) matched every /posts/* request, but it changes the response only for:
    • markdown requests (an Accept header naming text/markdown or text/x-markdown, or the .md suffix)
    • laptop-mirror document requests (dl_v=v2 cookie, not a _next/data request)
  • Over 12h in prod, that meant about 367K invocations that returned NextResponse.next(), against about 50K that rewrote. Vercel bills each one as a function invocation, and it runs in front of the CDN cache, so even cache hits paid for it.
  • The /posts/:path* matcher now uses has/missing conditions, so plain post requests skip the proxy and go straight to the cached page. /api/md/* and the .md pages stay unconditional.
  • acceptsMarkdown still makes the final decision, including the q-value comparison with text/html. The matcher only pre-filters on the media type appearing in Accept.

Tradeoffs:

  • The header pre-filter is case-sensitive (lowercase text/markdown). A client sending Text/Markdown would now get HTML instead of markdown. Every agent we see sends lowercase.
  • If a new behavior is added to the proxy for posts, the matcher has to be widened too. The matcher tests cover the current cases.

Events

No

Experiment

No

Manual Testing

Checked on the preview deployment:

  • Accept: text/markdown on /posts/<slug> returns markdown (proxy rewrite to /api/md/posts/[id])
  • Accept: text/html, text/markdown;q=0.5 returns HTML (proxy runs, acceptsMarkdown declines)
  • /posts/<id>.md returns markdown
  • dl_v=v2 returns x-layout-variant: v2 from /layout-v2/posts/[id]
  • Plain requests (dl_v=v1, HTML Accept, 11 requests) return HTML and log no middleware invocation; only the 4 requests above appear in the deployment's middleware metrics

https://claude.ai/code/session_01FodmVu2j66685xSYXwxrdd


Generated by Claude Code

The proxy matched every /posts/* request, but it only changes the response
for markdown requests (Accept header or .md suffix) and for laptop-mirror
document requests (dl_v=v2 cookie). Over 12h that was ~367K no-op
invocations vs ~50K rewrites, each billed as a function invocation in front
of the CDN cache.

Gate the post matcher on those conditions with has/missing so plain post
requests go straight to the cached page. The q-value logic stays in
acceptsMarkdown; the matcher only pre-filters on the media type appearing
in Accept (lowercase, as every agent we see sends it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FodmVu2j66685xSYXwxrdd
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
daily-webapp Ready Ready Preview Dec 3, 2026 12:56pm UTC

Request Review

@idoshamun idoshamun self-assigned this Dec 3, 2026
@idoshamun
idoshamun merged commit c0d1326 into main Dec 3, 2026
12 checks passed
@idoshamun
idoshamun deleted the webapp-proxy-matcher branch December 3, 2026 20:32

This branch was successfully deployed

1 active deployment
Preview — c1c0f8e4 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants