Spurious Pragma Header in Sitecore Page Responses

So, one of my colleagues contacted me with a simple question – why was Azure Front Door not caching his pages and images. Well, I think there were two different reasons; one for pages (discussed here) and one for images (discussed there).

The short answer for pages was “Because the setting DisableBrowserCaching was set to true”. This appears to be a default for Sitecore (and is probably appropriate for Analytics and tracking reasons – though not all of our customers use analytics). I mean, the setting in ShowConfig.aspx is pretty well described.

But wait… what’s this mention of Pragma: no-cache?

I checked in DevTools, and yup, there it was, like an crazy, drunk great-uncle that nobody could remember inviting to the family Christmas.

The Pragma header is a very old, inconsistently implemented, unclear and unreliable version of the Cache-Control header we all know and love. It’s deprecated, and I think shouldn’t be used at all; I mean, who really needs HTTP 1.0 backward compatibility these days?

Worse, my colleague had a rule in Front Door to overwrite the cache-control header (so it wasn’t no-cache, no-store), but then had this inconsistent value because he was also sending pragma: no-cache.

Naturally, I decided to find out where it was coming from, so I could configure it to not be sent. And down the rabbit hole I vanished.

It turns out that the browser cache control headers are set in the renderlayout pipeline…

However, internally, its not doing anything really weird (just usual levels of Sitecore weird). Follow through their code, you come to:

This is… fine, actually. But there’s no mention of Pragma headers? And that’s because the problem isn’t Sitecore, it’s actually .NET Framework. If you .SetCacheability(HttpCacheability.NoCache), well, internally it decides what you really need is an additional Pragma header.

That “magic 4” on the middle underline is the Pragma header.

So, how to fix it? Well, I would:

  • Patch and replace the Sitecore.Pipelines.RenderLayout.BrowserCaching processor
  • Do not use SetCacheability(). Set the Cache-Control header yourself, directly, using something like this example that is already in Sitecore.
Spurious Pragma Header in Sitecore Page Responses

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.