sw-precache 설명서의 내용에 따르면 sw-precache에 대한 런타임 캐싱 구성을 포함하여 https://github.com/GoogleChrome/sw-precache#runtime-caching은 동적 콘텐츠의 런타임 캐싱을 위해 sw-toolbox를 포함해야합니다. 나는 sw-precache의 CLI뿐만 아니라 grunt-sw-precache와 함께 이것을 사용하려고 시도했다. 그랑 트에 대한 내 구성은 다음과 같습니다 :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
}
}
}]
}
}
}});
그리고 CLI를 시도 할 때 내가 사용하는 다음과 같은 SW-미리 캐시-config.js 다음 runtimeCaching 옵션에 비해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
}
}
}]
};
모든 구성 옵션 다른 하나는 생성 된 서비스 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