sw-precacheのドキュメントhttps://github.com/GoogleChrome/sw-precache#runtime-cachingによると、sw-precacheのランタイムキャッシュ設定では動的コンテンツのランタイムキャッシュをsw-toolboxに含める必要があります。私はsw-precacheのCLIとgrunt-sw-precacheでこれを使用しようとしました。 Gruntの設定は以下の通りです。runtimeCachingで設定されたsw-precacheを使用していないsw-toolbox
grunt.initConfig({
'sw-precache': {
build: {
baseDir: './public',
workerFileName: 'service-worker.js',
appendTimestamp: true,
cacheId: 'cnbc-polymer-cache-20',
clientsClaim: true,
directoryIndex: 'index.html',
navigateFallback: 'index.html',
skipWaiting: true,
maximumFileSizeToCacheInBytes: (1024000 * 20),
staticFileGlobs: [
'/src/**/*',
'/index.html',
'/manifest.json',
'/bower_components/**/*',
'/images/**/*.*',
'/favicon.ico'
],
verbose: true,
runtimeCaching: [{
urlPattern: /franchise/,
handler: 'cacheFirst',
options: {
debug: true,
cache: {
maxEntries: 10,
name: 'franchise-cache',
maxAgeSeconds: 180
}
}
}, {
urlPattern: /story/,
handler: 'cacheFirst',
options: {
debug: true,
cache: {
maxEntries: 10,
name: 'story-cache',
maxAgeSeconds: 180
}
}
}]
}
}
});
とするとき、私は、次のSW-プリキャッシュ-config.jsの使用CLIをしよう:
module.exports = {
baseDir: './public',
workerFileName: 'service-worker.js',
appendTimestamp: true,
cacheId: 'cnbc-polymer-cache-20',
clientsClaim: true,
directoryIndex: 'index.html',
navigateFallback: 'index.html',
skipWaiting: true,
maximumFileSizeToCacheInBytes: (1024000 * 20),
staticFileGlobs: [
'/src/**/*',
'/index.html',
'/manifest.json',
'/bower_components/**/*',
'/images/**/*.*',
'/favicon.ico'
],
verbose: true,
runtimeCaching: [{
urlPattern: /franchise/,
handler: 'cacheFirst',
options: {
debug: true,
cache: {
maxEntries: 10,
name: 'franchise-cache',
maxAgeSeconds: 180
}
}
}, {
urlPattern: /story/,
handler: 'cacheFirst',
options: {
debug: true,
cache: {
maxEntries: 10,
name: 'story-cache',
maxAgeSeconds: 180
}
}
}]
};
runtimeCachingオプション以外のすべての設定オプションは、生成されたサービス・worker.jsファイルに適用されています。
私のpackage.jsonは、sw-precacheの "^ 4.2.3"とsw-toolboxの "^ 3.4.0"を使用するように設定されています。
私はこの問題を抱えているとコメントした人は他にいません。誰でもsw-precacheが私のruntimeCachingオプションを尊重することを妨げる問題が何であるかについてコメントできますか?
私はgrunt-sw-precacheをインストールしました。問題は、作成されたservice-worker.jsファイルにランタイムキャッシングコードがまったく含まれていないことです。 sw-toolboxは、直接、またはimportScriptsには含まれていません。生成されたtoolbox.router.get(...)呼び出しは、サービスワーカーファイルには存在しません。プリキャッシュロジックのみが生成されたファイルに含まれます。 – blissedout