Polymer / shop

The Shop app
https://shop.polymer-project.org/
986 stars 494 forks source link

Updates for differential serving. #121

Closed aomarks closed 7 years ago

aomarks commented 7 years ago

We want to demonstrate differential serving using shop as an example where we serve a different build (e.g. bundled/unbundled) to different user agents based on their capabilities (e.g. push).

The strategy we have settled on (cc @graynorton) is to switch the entrypoint we serve depending on user agent, where each entrypoint has a <base> tag pointing to its build sub-directory, so that we can then use relative links to point at the right static resources.

So, this PR updates shop to use relative links for static resources, and adds a default <base href="/"> tag (which we will automatically update from polymer build) so that the app behaves exactly as before when served from the root.

It also sets the service worker scope to / so that (in conjunction with a Service-Worker-Allowed header), service workers served from a build's sub-directory can intercept requests from all routes.

aomarks commented 7 years ago

Merging! (Talked with keanulee/frankiefu offline).

Thanks for the discussion. The other point keanulee brought up is that with this pattern we're duplicating static assets (images etc.) in multiple build directories, which is not ideal in terms of deploy size on disk, and also caching. It's conceivable that different builds would actually have different static files (e.g. higher image compression for a mobile build), but otherwise you would just use absolute URLs for shared assets, and lift them up a directory as a post-build step. That's something we could eventually add to the polymer tooling.