【问题标题】:How to cache webpack's assets and exclude index.html?如何缓存 webpack 的资产并排除 index.html?
【发布时间】:2020-06-20 02:48:31
【问题描述】:

我想优化我的 SPA 以缓存 webpack 的所有资产,以便它们在下次重新加载时加载得更快。

我不需要离线功能,我希望用户在重新加载页面后始终能够获得新版本,没有“新内容可用;请刷新”。消息。

据我所知,Webpack 在每个文件的名称中都包含哈希,因此文件名从一个版本到另一个版本是“唯一的”。所以我的策略是缓存除index.html 之外的所有内容。所以当用户点击重新加载时,他总是从服务器获取index.html,然后服务工作者为已经加载的文件提供缓存。

简单地说,我希望复制一个简单的缓存,例如使用标头 Cache-Control。

我应该使用workbox-webpack-pluginGenerateSW(config) 方法吗?如何将其配置为仅从缓存中排除 index.html 并包含其他所有内容?

【问题讨论】:

    标签: workbox workbox-webpack-plugin


    【解决方案1】:

    workbox-webpack-plugin 具有可用于排除 index.html 的排除选项。

    更多信息可以在这里找到:https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-webpack-plugin.GenerateSW#GenerateSW

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 2023-03-03
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2019-05-26
      • 2020-07-07
      • 2012-04-01
      • 2017-04-06
      相关资源
      最近更新 更多