Skip to content

Latest commit

 

History

History
106 lines (83 loc) · 4.84 KB

amp-install-serviceworker.md

File metadata and controls

106 lines (83 loc) · 4.84 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>
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 errors

The following lists validation errors specific to the amp-install-serviceworker tag (see also amp-install-serviceworker in the AMP validator specification):

Validation Error Description
The 'example1' tag is missing or incorrect, but required by 'example2'. Error thrown when required amp-install-serviceworker extension .js script tag is missing or incorrect.
Missing URL for attribute 'example1' in tag 'example2'. Error thrown when src attribute is missing its URL.
Malformed URL 'example3' for attribute 'example1' in tag 'example2'. Error thrown when src attribute's URL is invalid.
Invalid URL protocol 'example3:' for attribute 'example1' in tag 'example2'. Error thrown src attribute's URL is http; https protocol required.
The implied layout 'example1' is not supported by tag 'example2'. The only supported layout type is NODISPLAY. Error thrown if implied layout is any other value.
The specified layout 'example1' is not supported by tag 'example2'. The only supported layout type is NODISPLAY. Error thrown if specified layout is any other value.