rsnext/examples/amp-first/public/serviceworker.js
Sebastian Benz 79e717a76b Add AMP First example (#9109)
* Add AMP First example

The sample demonstrates how to build an AMP First Site with AMP. If
follows all the best-practices recommended by Lighthouse and will
result in a fully-qualified PWA.

Live demo of the page: https://my-next-app.sebastianbenz.now.sh/#development=1

* small improvements to AmpScript and AmpState

* remove gitignore

* Update example

* Move styles down in Layout

* Apply lint fix and tweak prop-types

* Add warning for host header usage
2019-11-10 21:30:36 -08:00

28 lines
948 B
JavaScript

/* global importScripts, AMP_SW */
importScripts('https://cdn.ampproject.org/sw/amp-sw.js')
/*
This configures the AMP service worker to enhance network resiliency and
optimizes asset caching. This configuration will:
- Cache AMP scripts with a stale-while-revalidate strategy for a longer duration
than the default http response headers indicate.
- Cache valid visited AMP documents, and serve only in case of flaky network conditions.
- Cache and serve an offline page.
- Serve static assets with a cache first strategy.
Checkout https://github.com/ampproject/amp-sw/ to learn more about how to configure
asset caching and link prefetching.
*/
AMP_SW.init({
assetCachingOptions: [
{
regexp: /\.(png|jpg|woff2|woff|css|js)/,
cachingStrategy: 'CACHE_FIRST', // options are NETWORK_FIRST | CACHE_FIRST | STALE_WHILE_REVALIDATE
},
],
offlinePageOptions: {
url: '/offline',
assets: [],
},
})