Should the Croct proxy matcher exclude _next/static and image routes?
I copied a minimal middleware file from an example while wiring up @croct/plug-next and only later noticed it had no config.matcher at all. Which means the Croct proxy is currently running on literally every request, including fonts, images and everything under _next/static.
Two questions:
- Does that actually hurt performance, or is the proxy cheap enough that it does not matter?
- What does the recommended matcher look like? I have seen a few variations and I want the one the docs intend.
The site is fine so far but we get a decent amount of traffic and I would rather fix this before it becomes a mystery later
2 answers
Yes, add the matcher. The documented setup ships with one for exactly this reason:
export const config = { matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],};The proxy exists to handle tokens and request context for page rendering. A request for a font file or a static chunk has no page to personalize, so running the proxy there adds latency and middleware invocations for zero value. It will not break anything, it is just pure waste.
On whether it "hurts": each asset request pays the middleware cost, and on a typical page that is dozens of requests. If you are on a platform that bills per middleware invocation you are also paying for it directly. So not a fire, but definitely fix it.
One thing I would add from experience: if you have other route groups that never render Croct content (webhook endpoints, health checks, a status page), you can extend the negative lookahead to skip those too. The pattern in the docs is the baseline, not a ceiling. Just be careful not to exclude actual page routes or the SDK will complain about the missing proxy on those pages.