Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withPWA precaches on every route, but I want it to do that only on specific routes #494

Open
EricDotSmith opened this issue Oct 7, 2023 · 0 comments

Comments

@EricDotSmith
Copy link

The main issue I'm trying to figure out right now is I noticed workbox/the service worker that withPWA sets up, starts precaching everything I specified but on EVERY route, such as our login page. But I would like to restrict this to just precache when on specific routes like /test or /other so it doesn't bog down my entire website for no reason.

Is there a way to do this. Here is my current config

await import("./src/env.mjs");
import { nanoid } from "nanoid";
import i18n from "./next-i18next.config.js";
import withPWA from "next-pwa";

const buildId = nanoid();

const pwa = withPWA({
  dest: "public",
  scope: "/test",
  additionalManifestEntries: [
    { url: "/logo.svg", revision: "1" },

    { url: "/test", revision: "1" },
    { url: "/other", revision: "1" },

    { url: "/en/test", revision: "1" },
    { url: "/en/other", revision: "1" },
    { url: `_next/data/${buildId}/en/test.json`, revision: "1" },
    { url: `_next/data/${buildId}/en/other.json`, revision: "1" },

    { url: "/es/test", revision: "1" },
    { url: "/es/other", revision: "1" },
    { url: `_next/data/${buildId}/es/test.json`, revision: "1" },
    { url: `_next/data/${buildId}/es/other.json`, revision: "1" },

    { url: `_next/data/${buildId}/en.json`, revision: "1" },
    { url: `_next/data/${buildId}/es.json`, revision: "1" },

    // ... other routes
  ],
});

/** @type {import("next").NextConfig} */
const config = pwa({
  generateBuildId: () => buildId,
  reactStrictMode: true,

  /**
   * If you have `experimental: { appDir: true }` set, then you must comment the below `i18n` config
   * out.
   *
   * @see https://github.com/vercel/next.js/issues/41980
   */
  i18n: i18n.i18n,
});

export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant