微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NEXP PWA /static/chunks 404 未找到

如何解决NEXP PWA /static/chunks 404 未找到

我是在 Nextjs 中使用 service worker 的新手,尝试了一切,但我没有结果,它没有捕获或没有更新一些动态导入的组件和应用程序崩溃,这是我使用工作箱的 service-worker.js 配置, 我已经尝试过 self.skipwaiting(),workBox-core skipwaiting(),在 next.config.js skipwaiting: true/false,不知道该怎么做:|:| 错误:GET 状态 404(未找到) http://localhost:3000/_next/static/chunks/components_navbar_desktop_NewNavbar_js.js

有人可以帮忙吗? 感谢您的关注

import { skipwaiting,clientsClaim } from 'workBox-core'
import { ExpirationPlugin } from 'workBox-expiration'
import { NetworkFirst,StaleWhileRevalidate } from 'workBox-strategies'
import { registerRoute,setCatchHandler } from 'workBox-routing'
import { matchPrecache,precacheAndRoute,cleanupOutdatedCaches } from 'workBox-precaching'

// self.skipwaiting()
clientsClaim()

// must include following lines when using inject manifest module from workBox
// https://developers.google.com/web/tools/workBox/guides/precache-files/workBox-build#add_an_injection_point
const WB_MANIFEST = self.__WB_MANIFEST
// Precache fallback route and image
WB_MANIFEST.push(
  {
    url: '/fallback',revision: '1234567890'
  }
)
precacheAndRoute(WB_MANIFEST)

cleanupOutdatedCaches()
registerRoute(
  '/',new NetworkFirst({
    cacheName: 'start-url',plugins: [new ExpirationPlugin({ maxEntries: 1,maxAgeSeconds: 86400,purgeOnQuotaError: true })]
  }),'GET'
)
// registerRoute(
//   /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,//   new CacheFirst({
//     cacheName: 'google-fonts',//     plugins: [new ExpirationPlugin({ maxEntries: 4,maxAgeSeconds: 31536e3,purgeOnQuotaError: true })]
//   }),//   'GET'
// )
registerRoute(
  new RegExp('\.(eot|otf|ttc|ttf|woff|woff2|font.css)$'),new StaleWhileRevalidate({
    cacheName: 'fonts',plugins: [new ExpirationPlugin({ maxEntries: 4,maxAgeSeconds: 604800,'GET'
)
// disable image cache,so we Could observe the placeholder image when offline
registerRoute(
  new RegExp('\.(jpg|jpeg|gif|png|svg|ico|webp)$'),new StaleWhileRevalidate({
    cacheName: 'images',plugins: [new ExpirationPlugin({ maxEntries: 64,'GET'
)
registerRoute(
  new RegExp('\.js$'),new StaleWhileRevalidate({
    cacheName: 'js',plugins: [new ExpirationPlugin({ maxEntries: 32,'GET'
)
registerRoute(
  new RegExp('(\/sales\/\d+)'),new StaleWhileRevalidate({
    cacheName: 'sale-pages','GET'
)
registerRoute(
  new RegExp('\.css$'),new StaleWhileRevalidate({
    cacheName: 'styles','GET'
)

registerRoute(
  /\.(json|xml|csv)$/i,new NetworkFirst({
    cacheName: 'static-data-assets','GET'
)

registerRoute(
  /.*/i,new NetworkFirst({
    cacheName: 'others',networkTimeoutSeconds: 10,'GET'
)

  switch (event.request.destination) {
    case 'document':
      // If using precached URLs:
      return matchPrecache('/fallback');
      // return caches.match('/fallback')
      break
    case 'image':
      // If using precached URLs:
      return matchPrecache('/static/images/fallback.png');
      // return caches.match('/static/images/fallback.png')
      break
    case 'font':
    // If using precached URLs:
    // return matchPrecache(FALLBACK_FONT_URL);
    //return caches.match('/static/fonts/fallback.otf')
    //break
    default:
      // If we don't have a fallback,just return an error response.
      return Response.error()
  }
})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。