7 comments

  • simonw3 hours ago
    I&#x27;ve been wanting this from Cloudflare <i>for years</i>.<p>The classic problem here is if you do that thing where user agents that send &quot;accept: text&#x2F;html&quot; get HTML, while user agents that don&#x27;t get JSON or some other format.<p>This used to be impossible to deploy behind Cloudflare caching, because they ignored the Vary header on anything other than images - so you risked caching the JSON version and then serving it up to someone who was expecting HTML.<p>(Independent of the Cloudflare feature I ended up deciding never to use that pattern, because I prefer having URL that predictably returns HTML or JSON - I add a .json suffix to my apps to serve JSON instead.)
    • Joker_vD40 minutes ago
      Frankly, the supposed variability of the Accept header never really sat all that well with me; in practice I much prefer working with explicitly versioned endpoints — one of the most infuriating things is having to hardcode &quot;Accept: text&#x2F;x-myorgname-custom-json-blob-v4&quot; because omitting it would produce &quot;406 Not Acceptable&quot;. Bonus points if that&#x27;s the <i>only</i> Accept header the service would ever accept in all of three years of it working before being decommissioned. Double bonus points if v5 would be introduced behind a separate URI anyway (and it, too, would require precisely &quot;Accept: text&#x2F;x-myorgname-custom-json-blob-v5&quot; and nothing else).
  • jrochkind12 hours ago
    I had not actually realized what a mess Vary is.<p>Wow, sometimes I think it&#x27;s amazing the web works at all!
    • saltcured2 hours ago
      It pains me to think about the important ones like varying on session cookie and authorization headers, and how badly some middleware can confuse things.<p>We generate custom content for a given authentication context. We definitely want caching at the user agent, but we want the cache keyed by the authenticated identity. Otherwise something like logging out and logging in as a different identity can produce monstrously confused results when an SPA or similar mixes some cached and some fresh responses into one page.
      • rmunn1 hour ago
        Cache invalidation, one of the two hard problems in computer science.<p>I&#x27;m sure most people here already knows the joke, but for the lucky 10,000, here&#x27;s the full joke:<p>There are only two hard problems in computer science. Naming things, cache invalidation, and off-by-one errors.
    • mikestorrent1 hour ago
      Imagine if we actually built a remote application delivery platform instead of cobbling one onto a glorified document reader
  • badlibrarian2 hours ago
    If this surprises you, remember that Cloudflare doesn&#x27;t cache HTML by default.
    • AlienRobot1 hour ago
      They can&#x27;t do that because a CMS under Cloudflare needs to be configured to bust the Cloudflare cache when content is edited or the user will see cached content after they edit a page.
      • tshaddox38 minutes ago
        That might be the default configuration if your CMS doesn&#x27;t return any cache-control headers. But Cloudflare definitely [0] supports must-revalidate and etag or last-modified, which is also probably supported by whatever CMS you&#x27;re using. HTTP conditional requests are very old and very widely supported.<p>[0] Okay, my claim is only <i>definite</i> up to my memory of using Cloudflare for a fairly high-traffic circa 2019-2022. I haven&#x27;t used Cloudflare after that point, but a quick search of their docs shows support
      • eli1 hour ago
        OTOH a CMS that doesn’t send correct cache headers is already broken
  • rob-olmos3 hours ago
    &quot;If the origin response does not include a Vary header, Cloudflare caches the response normally&quot;[1]<p>&quot;If one response omits it, Cloudflare could cache that response without the variance needed to keep it isolated.&quot;[2]<p>Will that non-Vary cache object front-run any Vary-segmented cache objects?<p>If so, probably worth adding a snippet rule to ensure every response has a Vary header?<p>1: <a href="https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;cache&#x2F;concepts&#x2F;vary&#x2F;#how-vary-affects-cache-keys" rel="nofollow">https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;cache&#x2F;concepts&#x2F;vary&#x2F;#how-v...</a><p>2: <a href="https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;vary-support&#x2F;#how-a-response-moves-through-cache" rel="nofollow">https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;vary-support&#x2F;#how-a-response-mov...</a>
  • bhouston3 hours ago
    Nice to see. I’ve used vary to quite a bit of success on CloudFront back in the day.<p>I actually assumed when I started using Cloudflare that it did have vary support and it led to a serious bug in my sass app at the time.
  • xyzzy_plugh3 hours ago
    I honestly thought they would never ship this. Holy hell this has been a long time coming.<p>Actual real content negotiation in 2026. Never thought I&#x27;d live to see the day.
  • rgbrenner2 hours ago
    finally. now maybe they&#x27;ll have time to implement a working unsubscribe on their marketing emails.
    • shermantanktop2 hours ago
      Turns out their marketing can get to you through HN posts…