5 ms·
I would love to jump over to something like Vercel or Netlify Edge, but maddeningly none of these platforms give you control over the cache key. I have pages th
by dbbk 5y ago
I would love to jump over to something like Vercel or Netlify Edge, but maddeningly none of these platforms give you control over the cache key. I have pages that are server-side rendered with Cache-Control headers, but because our visitors come with unique tracking params on the end of their URL (e.g. from Mailchimp or Branch), we would essentially have no cache hits.
It seems the only way to have control over this is to write your own Cloudflare Workers. There must be a better way? I can't imagine this is an infrequent problem for people at scale.
- bobfunk 5y agoSo far Netlify Edge Functions runs before the cache layer, so you can actually use a minimal function to rewrite the URL to remove all unique params, etc, and then let it pass through our system to a Netlify Function which runs behind our caching layer. For anything you can do at build time as a static HTML pages we already strip query parameters from cache keys.
- dbbk 5y agoInteresting, thanks... do you have any docs on how we might achieve this with Next.js? Am I right in thinking we would have essentially a custom Edge Function first that handles query params, and then a second Edge Function that renders the Next app?
- ascorbic 5y agoI work at Netlify on framework integrations. Next has beta support for running the whole app at the edge, and Netlify supports that. If you create you own custom edge functions they will run first, so you can do just that. You can also run Next "normally" (i.e. in the node-based Netlify Functions) and run your own edge functions in front of that. In those you can modify the Request in any way you'd like, before passing it on to the origin.
- dbbk 5y agoYeah I'm very intrigued by running the whole app on the edge (in their Edge Runtime). This sounds pretty promising. I'll take a dive and see if I can get it working, thanks for the tip!
- cxr 5y ago> There must be a better way? You're experiencing friction trying to use something in a way that it's supposed to not be used. (I.e., click-tracking by junking up URLs.) You could look for an answer, or you could take a step back, evaluate your expectations, and then decide not to do what you're trying to do.
- eli 5y agoCloudflare Transform Rules let you rewrite URLs on the fly https://developers.cloudflare.com/rules/transform/ https://developers.cloudflare.com/rules/transform/
- patches11 5y agoWhy don't you just link to an API route, consume the tracking params, set a cookie, and redirect to a statically rendered page?
- teaearlgraycold 5y agoTime to first paint
- ianand 5y agoI'm biased but there is a better way. Give developers a high performance method programmatically manipulating the cache key from JavaScript. That's what we created with EdgeJS: https://docs.layer0.co/guides/caching https://docs.layer0.co/guides/caching It's less work to write and higher performance than dealing with edge functions or worker for routine tasks like this.