Polymer/prpl-server

Entrypoint should have vary: user-agent header

arthurevans opened this issue · 4 comments

It appears that prpl-server serves all files with vary: accept-encoding. As I understand it, that will cause edge caches to cache the file incorrectly. I think it should be vary: accept-encoding, user-agent for the entrypoint.

Currently everything is served with cache-control:public, max-age=0, which is the express/send default. max-age=0 should mean that vary is irrelevant, since nothing will be cached anyway. We do have etag support.

So if we do this, we first need to figure out the story for cache headers more generally.

I think we can say that if you have a service worker, these headers are pretty much irrelevant for the browser? So that leaves Safari, Edge, and CDN edge caching behavior to think about, I think?

Ah, I missed the max-age there.

I was thinking about the caching infrastructure on the serving side. I believe a hosting solution may include edge caches between the node that terminates the HTTPS connection and the node that actually serves the content. If you didn't have max-age=0, those edge caches could cache a response to a Chrome user, for example, and return it to a subsequent request from a Firefox user, for instance.

That shouldn't happen with max-age=0, but that also probably isn't a good default for performance, both on the server side or the (non-SW) client side. And that needs to be potentially configured on a per-URL basis.

So, yes, this is probably part of a larger discussion on caching.

Setting things to be non-cacheable when a service worker is involved works great but it does make things sub-optimal for browsers lacking sw support as they will be downloading the entire app content on each visit (and from the origin server, never the faster edge / CDNs).

There are also issues with setting things to be cachable when it comes to which versions of elements and dependencies might still be in a browsers cache leading to errors from mis-matched versions, i.e. the max-age gotcha

What about, for non-sw browsers, the build name is combined with some version hash of the build? This would keep all the dependencies as a cohesive unit while allowing long cache times to be used (for the non index.html content).

Edited to add: even for browsers with a service worker, the cache headers will definitely benefit their first view if it means they can load assets from a shorter network hop (edge / CDN) instead of a full request back to the origin server.

Closing because prpl-server is now in maintenance mode. See https://github.com/Polymer/prpl-server#prpl-server for our recently added maintenance mode notice, and recommendations for alternatives.