text: self.__precacheManifest = self.__precacheManifest || [];
  
  const isAmpPage = pathname =>
    [
      //
      /^\/$/,
      /^\/about$/,
      /^\/movie\/[^\/]+$/
    ].some(re => pathname.match(re));
  
  /**
   * get the hash generated by next
   * which will be used as cache buster for additional asset that we will add
   */
  const hash = __precacheManifest.reduce((h, { url }) => {
    const m = url.match(/static\/(?<hash>[^\/]+)\/pages\//);
    return h || (m && m.groups.hash);
  }, null);
  
  const appRootUrl = "/?__WB_REVISION__=" + hash;
  
  const appShellUrl = "/pwa-shell?__WB_REVISION__=" + hash;
  
  const ampScriptUrl = "/assets/fav-button-script.js?__WB_REVISION__=" + hash;
  
  const removeTrailingSlash = s =>
    "/" +
    s
      .split("/")
      .filter(Boolean)
      .join("/");
  
  /**
   * pre cache assets
   */
  workbox.precaching.precacheAndRoute([
    appRootUrl,
  
    appShellUrl,
  
    ampScriptUrl,
  
    ...__precacheManifest
  
      // filter out amp page,
      // which actually don't have any js chunk related to them, even if it's listed in the manifest
      .filter(x => {
        const m = x.url.split("?")[0].match(/pages(\/.*)\.js/);
  
        if (!m) return true;
  
        const pathname = removeTrailingSlash(m[1].replace(/index/, ""));
  
        return !isAmpPage(pathname);
      })
  
      // rewrite the route,
      // because nextjs does it
      .map(x => ({
        ...x,
        url: x.url.replace(/^static\//, "_next/static/")
      }))
  ]);
  
  /**
   * cache pages
   */
  workbox.routing.registerRoute(
    ({ url, event }) =>
      [
        //
        /\/movie\/[^/]+/,
        /\/api\/.*/
      ].some(re => url.pathname.match(re)),
  
    new workbox.strategies.StaleWhileRevalidate({
      cacheName: "content-cache",
      plugins: [
        new workbox.expiration.Plugin({
          maxAgeSeconds: 24 * 60 * 60,
          maxEntries: 20
        })
      ]
    })
  );
  
  /**
   * upon navigation, serve the pwa shell instead
   */
  workbox.routing.registerRoute(
    ({ url, event }) =>
      event.request.mode === "navigate" && isAmpPage(url.pathname),
  
    async ({ url, event, params }) => {
      console.log("navigation, push shell instead", url.pathname);
  
      const cache = await caches.open(workbox.core.cacheNames.precache);
      const response = await cache.match(
        workbox.precaching.getCacheKeyForURL(appShellUrl)
      );
  
      if (response) return response;
      else {
        const res = await fetch(appShellUrl);
  
        cache.put(appShellUrl, res.clone());
  
        return res;
      }
    }
  );
  