【问题标题】:Workbox CacheFirst Strategy Issue for PWA Created Using Vue CLI 3使用 Vue CLI 3 创建的 PWA 的 Workbox CacheFirst 策略问题
【发布时间】:2019-05-04 11:42:39
【问题描述】:

我的 PWA,最近使用 Vue CLI 3 创建,效果很好,只是我无法让它缓存我的字体超过max-age=0

这是我的设置:

vue.config.sys(适用部分)

module.exports = {
  pwa: {
    workboxOptions: {
      exclude: [/\.eot$/, /\.ttf$/],
      clientsClaim: true,
      skipWaiting: true,
      navigateFallback: 'index.html',
      runtimeCaching: [
        {
          urlPattern: /\.(?:woff|woff2)$/,
          handler: 'cacheFirst',
          options: {
            // Use a custom cache name for this route.
            cacheName: 'fonts',
            // Configure custom cache expiration.
            expiration: {
              maxEntries: 50,
              maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
              // Automatically cleanup if quota is exceeded.
              purgeOnQuotaError: true,
            },
          },
        },
      ],
    },
  },
};

结果 service-worker.js(使用默认 GenerateSW 模式)

.htaccess(文件夹应用程序来自)

RewriteEngine On

# Redirects http calls to their equivalent https URL
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# A simple catch-all fallback route used when the URL entered by the user
# doesn't match any of the provided app routes. This code is needed when
# using history mode in vue-router.
FallbackResource index.html

# Prevents directory viewing from a browser window.
Options -Indexes

Chrome Dev Tools Cache Storage Screen Grab

我错过了什么?

【问题讨论】:

    标签: vuejs2 service-worker progressive-web-apps cache-control workbox-webpack-plugin


    【解决方案1】:

    您在 DevTools 的缓存存储查看器中看到的 Cache-Control 标头是您的 Web 服务器最终设置的任何内容 Cache-Control 标头值workbox-cache-expiration 在确定时使用不过,在缓存条目过期之前要等待多长时间。

    根据您所展示的内容,看起来您应该得到您期望的行为,即只要不违反maxAgeSecondsmaxEntries 约束,服务工作者就会使用缓存的字体。

    那么...您是否真的看到 Workbox 无法使用缓存的字体?

    【讨论】:

    • 没有记录失败,但那是因为我没有测试失败。我非常关注 Cache-Control 标头内容。所以它起作用了;那挺好的。谢谢你的解释。我没有看到这种行为记录在案,但我看到你确实提到了它here。因此,无法在开发工具中直观地检查 Workbox 在“过期”之前缓存文件多长时间?实证测试是(唯一)确定的方法吗?
    猜你喜欢
    • 2019-07-18
    • 1970-01-01
    • 2020-05-28
    • 2019-03-18
    • 2021-06-16
    • 2020-03-24
    • 2021-10-10
    • 2016-08-27
    • 1970-01-01
    相关资源
    最近更新 更多