GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 332 forks source link

A misplaced successResponses value can create an invalid service worker #260

Open arackaf opened 6 years ago

arackaf commented 6 years ago

First, can I ask if sw-precache will continue to be maintained? It appears as though

https://workboxjs.org/

is set up to replace this?


This configuration

        new SWPrecacheWebpackPlugin({
            runtimeCaching: [{
                urlPattern: /junk\/file1a\.js\?ver=.*/,
                handler: 'cacheFirst',
                options: {
                    cache: {
                        maxEntries: 1,
                        name: 'dist-resources'
                    },
                    successResponses: /200/,
                },
            }],

works fine, but, for those users unsure where to put successResponses (it doesn't seem to be documented), if they put it inside the cache object

        new SWPrecacheWebpackPlugin({
            runtimeCaching: [{
                urlPattern: /junk\/file1a\.js\?ver=.*/,
                handler: 'cacheFirst',
                options: {
                    cache: {
                        maxEntries: 1,
                        name: 'dist-resources',
                        successResponses: /200/,
                    },
                },
            }],

then the service worker gets generated with this

toolbox.router.get(/junk\/file1a\.js\?ver=.*/, toolbox.cacheFirst, {"cache":{"maxEntries":1,"name":"dist-resources","successResponses":{}}});

where successResponses.test will now of course be undefined.