GoogleChrome / workbox

📦 Workbox: JavaScript libraries for Progressive Web Apps
https://developers.google.com/web/tools/workbox/
MIT License
12.3k stars 811 forks source link

maxEntries and maxAgeSeconds not working #3257

Closed Viktor-as closed 5 months ago

Viktor-as commented 12 months ago

Browser & Platform: Google Chrome Version 117.0.5938.150

Issue or Feature Request Description: Hi, in Next Js I use @ducanh2912/next-pwa library to integrate workbox into Next Js. I am caching images and I want the cache to delete it self every day and not to cache more then for example 50 images - but its not working.

This is my next.config.js:

// @ts-check
/** @type {import('next').NextConfig} */
const { i18n } = require('./next-i18next.config');
const withTranslateRoutes = require('next-translate-routes/plugin');
const runtimeCaching = require('./services/cache');

const withPWA = require('@ducanh2912/next-pwa').default({
  dest: 'public',
  register: true,
  fallbacks: {
    image: '/offline/offline.png',
  },
  disable: process.env.NODE_ENV === 'development',
  workboxOptions: {
    runtimeCaching: runtimeCaching,
    cleanupOutdatedCaches: true,
  skipWaiting: true,
  },
  cacheOnFrontEndNav: false,
  reloadOnOnline: true,
});

const nextConfig = withPWA(
  withTranslateRoutes({
    webpack: (config) => {
      config.module.rules.push({
        test: /\.svg$/,
        use: [{ loader: '@svgr/webpack', options: { icon: true } }],
      });
      return config;
    },
    pageExtensions: ['tsx', 'js'],
    i18n,
    reactStrictMode: false,
  })
);
module.exports = nextConfig;

I import my runtimeCaching rules from another file ./services/cache.js it has this code:

module.exports = [
{
    urlPattern: ({ request, url, sameOrigin }) => {
      //other images
      if (!sameOrigin) return false;
      if (url.pathname === '/_next/image') {
        return true;
      }
      return false;
    },
    handler: 'NetworkFirst',
    options: {
      cacheName: 'other-images',
      expiration: {
        maxEntries: 20,
        maxAgeSeconds: 60, // 1 min
      },
    },
  },
]

So I am able to cache all images, but maxEntries: 20 and maxAgeSeconds: 60, does not work. In chrome dev tools I see in the cache like 100+ images, and they do not disappear after 1 min. My PWA app gets very big, very fast.

tomayac commented 5 months ago

Hi there,

Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:

Thanks, and we hope for your understanding! The Workbox team