[英]Bulk Add All (*.js) or (*.css) files to service worker cache on install
If I have a service worker registered with the doc root ( / ) as its scope, And my Document Layout is like so: 如果我有一个服务工作人员注册了文档根目录(/)作为其范围,并且我的文档布局是这样的:
How Do I Add All JS Only/CSS Only files to the service worker cache On Install and exclude other extensions Under each Directory? 如何将所有仅JS / CSS的文件添加到服务工作者缓存中在安装时排除每个目录下的其他扩展名?
I recommend using a utility like sw-precache that will take care of generating the service-worker.js file. 我建议使用诸如sw-precache之类的实用程序,该实用程序将负责生成service-worker.js文件。
Here's an example from one of my projects. 这是我的一个项目的示例。 You can change the glob pattern to fit your needs.
您可以更改glob模式以适合您的需求。
const swPrecache = require('sw-precache')
swPrecache.write('./public/service-worker.js', {
root: './public/',
staticFileGlobs: ['./public/**/*'],
stripPrefix: './public/'
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.