Skip to content

Latest commit

 

History

History
99 lines (79 loc) · 3.98 KB

amp-install-serviceworker.md

File metadata and controls

99 lines (79 loc) · 3.98 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
TAG_REQUIRED_BY_MISSING Error thrown when required amp-install-serviceworker extension .js script tag is missing or incorrect.
MISSING_URL Error thrown when src attribute is missing it's URL.
INVALID_URL Error thrown when src attribute's URL is invalid.
INVALID_URL_PROTOCOL Error thrown src attribute's URL is http; https protocol required.
IMPLIED_LAYOUT_INVALID The only supported layout type is NODISPLAY. Error thrown if implied layout is any other value.
SPECIFIED_LAYOUT_INVALID 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.