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 |
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>
URL of the ServiceWorker to register.
URL of a HTML document that install a ServiceWorker.
Must have the value nodisplay
.
See amp-install-serviceworker rules in the AMP validator specification.