Skip to content

Latest commit

 

History

History
99 lines (79 loc) · 4.41 KB

amp-install-serviceworker.md

File metadata and controls

99 lines (79 loc) · 4.41 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

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 it's 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.

Behavior

Registers the ServiceWorker given by the src attribute. If the current origin is different from the origin of the ServiceWorker, this custom element does nothing (emits warning in development mode).

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"
      layout="nodisplay">
  </amp-install-serviceworker>

Attributes

src

URL of the ServiceWorker to register.

layout

Must have the value nodisplay.