goldhand / sw-precache-webpack-plugin

Webpack plugin that generates a service worker using sw-precache that will cache webpack's bundles' emitted assets. You can optionally pass sw-precache configuration options to webpack through this plugin.
MIT License
1.44k stars 104 forks source link

Looking for Feature Like importScripts but For Static Results Outside of Webpack #151

Open ava-cassiopeia opened 6 years ago

ava-cassiopeia commented 6 years ago

webpack version: 4.5.0

sw-precache-webpack-plugin version: 0.11.5

Please tell us about your environment: OSX 10.x

Browser: Chrome 66

Current behavior:

There is no way (that I know of) to do something like importScripts but for static HTML pages that are not a part of the Webpack build.

Expected/desired behavior:

Some sort of option for importScripts but it's just importStatic or similar so that the service worker will cache static pages of HTML.

Example:

const swGenerator = new SWPrecacheWebpackPlugin({
    /* ... */
    importStatic: ["/", "/foo", "/bar"]
});

☝🏻That would cause the service worker to cache the HTML present in the result of those URLs.

Additional context:

I'm using Laravel + Vue.js, so the Laravel bits are responsible for certain URLs returning certain HTML, so webpack doesn't know about any of the files being outputted because it's dynamically generated and served by Laravel. Maybe I'm just holding it wrong for this plugin, but I can't find a way to get it to generate a service worker file that includes certain, arbitrary URLs to be precached as well.

ddykhoff commented 6 years ago

I think you are looking for staticFileGlobs, which you'll want to use in conjunction with mergeStaticsConfig: true.

kimown commented 5 years ago

I think you maybe use runtimeCaching

https://github.com/goldhand/sw-precache-webpack-plugin/issues/137#issuecomment-374293142