offline-plugin icon indicating copy to clipboard operation
offline-plugin copied to clipboard

Only cache *.js and *.css

Open praneshr opened this issue 8 years ago • 1 comments

Thanks for the great plugin. I'm using offline-plugin for a react app. It's an isomorphic app. My problem is, all my network calls are served from the serviceworker. Let me explain.

My config

    new OfflinePlugin({
        caches: {
          main: [
            '*.js',
            '*.css',
            '/offline',
          ],
        },
        autoUpdate: true,
        version: () => { },
        ServiceWorker: {
          output: '../sw.js',
          navigateFallbackURL: '/offline',
          navigateFallbackForRedirects: false,
          publicPath: '/sw.js',
          minify: true,
          prefetchRequest: {
            credentials: 'same-origin',
          },
        },
        AppCache: false,
      }),

But when I do a request for /category or /login, the HTML is also being served from the cache. The problem is it's not giving the latest HTML. Attaching the network waterfall.

image

**Is there a way not to serve HTML from the serviceworker? or just serve .js and .css from the cache?

praneshr avatar Jan 04 '18 05:01 praneshr

What I did (not sure if it's correct, but it works) was add some tests to ServiceWorker.navigationPreload.test. My usecase was that I didn't want files from a specific folder to be handled by the serviceworker, like videos.

ServiceWorker:{
    navigationPreload: {
        test: (url) => {
            // return false if you don't want the sw to handle the traffic
        }
    }
}

jbreemhaar avatar Feb 16 '18 10:02 jbreemhaar