With modern HTML5 history navigation, you typically need server support to render the same page for a variety of routes. But browsers aren’t going to know this is the same across multiple URLs - given a web app at https://example.com/app/
, if you first visit /app
and then a few days later open a new tab to /app/1/view
, the browser will see the second URL isn’t in the cache, despite it requiring basically the same set of files.
For this reason, I suggest there should be a Cache-Path: /path/to/parent
header, usable for all cacheable responses as well as 304s. This would tell the client to cache the response as if the request was to the following URL, and to read from the cache similarly. This may include query strings, which are considered part of the cache key. If missing, the default value is just the request path itself. This added to encourage correct caching behavior for SPAs, one that also ends up taking a lot less cache space. It would also allow better caching for other requests where query strings are not used to control server actions and responses, like with removing referrer strings and other SEO junk from the cache path so browsers don’t cache https://example.com/?_ref=foo
differently from https://example.com/
.