shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.75k stars 311 forks source link

cacheOnFrontEndNav not working #410

Open nikandlv opened 1 year ago

nikandlv commented 1 year ago

Summary

Here is my code

The issue is when i load the main page it caches every single resource i dont even in this page!

Reverting to next-pwa: 5.2.0 works

let withPWA = require('next-pwa')({
  cacheOnFrontEndNav: false,
  register: true,
  skipWaiting: true,
  maximumFileSizeToCacheInBytes: 10485760,
  scope: '/',
  dest: 'public',
  sw: 'service-worker.js',
  runtimeCaching: [
    {
      urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-font-assets',
        expiration: {
          maxEntries: 4,
          maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
        },
      },
    },
    {
      urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-image-assets',
        expiration: {
          maxEntries: 64,
          maxAgeSeconds: 24 * 60 * 60, // 24 hours
        },
      },
    },
    {
      urlPattern: /\.(?:css|less)$/i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-style-assets',
        expiration: {
          maxEntries: 16,
          maxAgeSeconds: 24 * 60 * 60, // 24 hours
        },
      },
    },
    {
      urlPattern: /\.(?:json|xml|csv)$/i,
      handler: 'StaleWhileRevalidate',
      options: {
        cacheName: 'static-data-assets',
        expiration: {
          maxEntries: 16,
          maxAgeSeconds: 24 * 60 * 60, // 24 hours
        },
      },
    },
  ],
})

Versions

How To Reproduce

Steps to reproduce the behavior:

  1. Build the project
  2. Run and visit the build in browser

Expected Behaviors

Only cache the resources on current page