Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 2.91 KB

amp-install-serviceworker.md

File metadata and controls

78 lines (56 loc) · 2.91 KB

amp-install-serviceworker

Description Installs a ServiceWorker for the current page.
Availability Stable
Required Script <script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>
Supported Layouts nodisplay
Examples None

Behavior

Registers the ServiceWorker given by the src attribute if the AMP document is loaded from the same origin as the given ServiceWorker URL. If the data-iframe-src is set, loads that URL as an iframe when the AMP document is served from an AMP cache. This allows ServiceWorker installation from the AMP cache, so that the ServiceWorker is installed by the time users visit the origin site.

This ServiceWorker runs whenever the AMP file is served from the origin where you publish the AMP file. The ServiceWorker will not be loaded when the document is loaded from an AMP cache.

See this article for how ServiceWorkers can help with making the AMP experience awesome with ServiceWorkers.

Example

  <amp-install-serviceworker
      src="https://www.your-domain.com/serviceworker.js"
      data-iframe-src="https://www.your-domain.com/install-serviceworker.html"
      layout="nodisplay">
  </amp-install-serviceworker>

Attributes

src

URL of the ServiceWorker to register.

data-iframe-src (optional)

URL of a HTML document that install a ServiceWorker.

layout

Must have the value nodisplay.

Validation

See amp-install-serviceworker rules in the AMP validator specification.