amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-install-serviceworker: support cross-origin SW installation

Open jmadler opened this issue 11 years ago • 6 comments

Support cross-origin SW installation (somehow)

This will enable folks to install service workers when an AMP HTML file is loaded from the AMP Cache

jmadler avatar Nov 20 '15 03:11 jmadler

What's the objective here? importScripts() works cross-origin, so you really only need a stub service worker on the CDN itself. (Which it probably doesn't support right now, but still, supporting that might make for an easier "fix".) importScripts() does make upgrading the service worker more difficult.

ithinkihaveacat avatar Dec 01 '15 17:12 ithinkihaveacat

@jmadler is looking for the ability for the page on the CDN to install a SW that would only be active on the origin of the doc. I'm not currently convinced we actually want to to support that.

Letting people install SWs on the CDN isn't entirely crazy, but would require a lot of thought.

cramforce avatar Dec 01 '15 17:12 cramforce

For context: https://github.com/ampproject/amphtml/pull/954#discussion-diff-45132552

jmadler avatar Dec 01 '15 20:12 jmadler

Sorry for the slow reply.

It's worth noting that a Service Worker can be installed via an <iframe> element. The way you might structure this in AMP is something along the lines of:

<!doctype html>
<html>
<!-- article.html, hosted at either:
  https://cdn.example.com/..../article.html
  https://originalsite.com/.../article.html
-->
<head>
  <title>...</title>
  <link rel="canonical" href="https://originalsite.com/.../article.html" >
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
  <script src="https://cdn.ampproject.org/v0.js" async></script>
  <style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript>
  <style amp-custom>
    ...
  </style>
  </style>
</head>
<body>
<amp-iframe width=1 height=1
    sandbox="allow-scripts"
    layout="responsive"
    frameborder="0"
    src="https://originalsite.com/serviceworker_bootstrap.html">
</amp-iframe>
</body>
</html>

This allows any AMP article to bootstrap a SW for navigations to the eventual origin.

slightlyoff avatar Dec 15 '15 01:12 slightlyoff

I don't think this is something we want to do. Please object strongly if you feel otherwise.

cramforce avatar Mar 07 '16 18:03 cramforce

Please re-open this discussion.

adewale avatar Mar 21 '16 19:03 adewale