Workbox:Strategies
Stale-while-revalidate example
workbox.routing.registerRoute(
/\.(?:js|css|webp|png|svg)$/,
new workbox.strategies.StaleWhileRevalidate()
);
Network First
- Navigation Preload for Network-first HTML - Chrome Developers
- javascript - exclude index.html from service worker cache in create-react-app - Stack Overflow
- Workbox Strategies with examples and use-cases | harrytheo.com
- Network-first Pre-cached PWA Start URLs with Workbox | Micah Engle-Eshleman
create-react-app에서의 index.html 캐시 처리 방법
cra-template-pwa(npx create-react-app my-app --template cra-template-pwa
)와 함께 create-react-app을 사용한 경우 사전 캐시한 다음 인덱스를 등록할 때 index.html
을 필터링할 수 있습니다. 네트워크 우선이 되도록 변경하십시오:
import { NetworkFirst } from 'workbox-strategies'
// precacheAndRoute(self.__WB_MANIFEST)
const toPrecache = self.__WB_MANIFEST.filter(
(file) => !file.url.includes('index.html'),
)
precacheAndRoute(toPrecache)
registerRoute(
({ url }) => url.pathname.includes('index.html'),
new NetworkFirst(),
)
그런 다음 모든 탐색 요청을 index.html로 라우팅하는 부분을 제거해야 합니다.
// Set up App Shell-style routing, so that all navigation requests
// are fulfilled with your index.html shell. Learn more at
// https://developers.google.com/web/fundamentals/architecture/app-shell
// const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$')
// registerRoute(
// // Return false to exempt requests from being fulfilled by index.html.
// ({ request, url }) => {
// // If this isn't a navigation, skip.
// if (request.mode !== 'navigate') {
// return false
// } // If this is a URL that starts with /_, skip.
// if (url.pathname.startsWith('/_')) {
// return false
// } // If this looks like a URL for a resource, because it contains // a file extension, skip.
// if (url.pathname.match(fileExtensionRegexp)) {
// return false
// } // Return true to signal that we want to use the handler.
// return true
// },
// createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html', true),
// )