내 웹 사이트 서비스 종사자 설정에 문제가 있습니다.서비스 종사자와 start_url 캐싱 방지
CSS/js/font 및 일부 이미지/svg 만 캐시하고 싶습니다. 매분마다 모든 정보가 업데이트되므로 HTML을 캐시하고 싶지는 않습니다.
다소 효과가 있지만 내 스마트 폰에서 이미 내가 추가 한 경우에도 "홈 화면에 추가"알림이 계속 표시됩니다. Chrome Dev 앱에서는 추가 버튼이 표시되지 않습니다.
또한 등대와 나는 다음과 같은 오류를 얻을 :
이"사용자가 웹 응용 프로그램을 설치하라는 메시지가 표시되지 않습니다 , 실패 "는 오프라인 200 때 응답하지 않습니다 "매니페스트 START_URL가 아닌 서비스 근로자가 캐시합니다. "
지금 내 sw.js는 다음과 같습니다. 보시다시피 나는 HTML을 캐싱하고 쿠키가 작동하지 않았기 때문에 가져 오기 부분에 주석을 달았습니다.
간단한 서비스 근로자 "템플릿"을 사용할 수 있습니까?
const PRECACHE = 'app-name';
const RUNTIME = 'runtime';
// A list of local resources we always want to be cached.
const PRECACHE_URLS = [
'/css/file.css',
'/js/file.js',
'/images/logo.png',
'/fonts/roboto/Roboto-Regular.woff2'
]
// The install handler takes care of precaching the resources we always need.
self.addEventListener('install', event => {
event.waitUntil(
caches.open(PRECACHE)
.then(cache => cache.addAll(PRECACHE_URLS))
.then(self.skipWaiting())
);
});
// The activate handler takes care of cleaning up old caches.
self.addEventListener('activate', event => {
const currentCaches = [PRECACHE, RUNTIME];
event.waitUntil(
caches.keys().then(cacheNames => {
return cacheNames.filter(cacheName => !currentCaches.includes(cacheName));
}).then(cachesToDelete => {
return Promise.all(cachesToDelete.map(cacheToDelete => {
return caches.delete(cacheToDelete);
}));
}).then(() => self.clients.claim())
);
});
// The fetch handler serves responses for same-origin resources from a cache.
// If no response is found, it populates the runtime cache with the response
// from the network before returning it to the page.
self.addEventListener('fetch', event => {
// Skip cross-origin requests, like those for Google Analytics.
// if (event.request.url.startsWith(self.location.origin)) {
// event.respondWith(
// caches.match(event.request).then(cachedResponse => {
// if (cachedResponse) {
// return cachedResponse;
// }
// return caches.open(RUNTIME).then(cache => {
// return fetch(event.request).then(response => {
// // Put a copy of the response in the runtime cache.
// return cache.put(event.request, response.clone()).then(() => {
// return response;
// });
// });
// });
// })
// );
// }
});