NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.52k stars 295 forks source link

Question - SW caching all assets site-wide #481

Closed Theo-Le-Donne closed 4 years ago

Theo-Le-Donne commented 4 years ago

Hi, After migrating ~150 pages, with all their specific assets imported dynamically, i just realized that SW was caching all assets (mostly images) of the whole website on the first request (thats about 30MB), regardless of the current page. The problem is that its making the perf go down of the current page, delaying the FCP, speed index etc... I was just wondering if thats a normal behaviour or if it's due to some config ? Should not all unnecessary assets be loaded after the current page is rendered ?

I use the default config for offline-plugin from react-boilerplate:

new OfflinePlugin({
      relativePaths: false,
      publicPath: '/',
      appShell: '/',

      excludes: ['.htaccess'],

      caches: {
        main: [':rest:'],
        additional: ['*.chunk.js'],
      },

      safeToUseOptionalCaches: true,
    }),

and also with the following cache config (same behaviour) :

caches: {
        main: [':rest:'],
        optional: ['*.chunk.js', '*.jpg'],
      },

When i remove the offline-plugin, everything is just requested as usual, what the current page needs.

Theo-Le-Donne commented 4 years ago

Closing this, That might be a really pad practice but setting up offline-plugin like this solved my issue :

caches: {
        main: ['index.html'],
        additional: [],
        optional:[:rest:]
      }