1

我最近使用 Vue CLI 3 创建的 PWA 效果很好,只是我无法让它缓存我的字体超过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 模式)

服务工作者.js

.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

Chrome 开发工具缓存存储的屏幕截图

我错过了什么?

4

1 回答 1

1

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

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

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

于 2018-12-06T18:51:55.640 回答