鍍金池/ 問答/HTML/ sw-precache-webpack-plugin怎么緩存cdn的數(shù)據(jù)呢

sw-precache-webpack-plugin怎么緩存cdn的數(shù)據(jù)呢

用sw-precache-webpack-plugin 放在同域名下可以offline,但是我把靜態(tài)文件放到CDN上就,一直失敗報:

An unknown error occurred when fetching the script.
service-worker.js Failed to load resource: net::ERR_INTERNET_DISCONNECTED

有人知道怎么配置CDN嗎?

回答
編輯回答
淚染裳

// 需要根據(jù)路由動態(tài)處理的文件

runtimeCaching: [
    // 如果在staticFileGlobs中設置相同的緩存路徑,可能導致此處不起作用
    {
        urlPattern: /\/js\//,
        handler: 'fastest',
        options: {
            cache: {
                maxEntries: 10,
                name: 'js-cache'
            }
        }
    },
    {
        urlPattern: /\/fonts\/|\.ttf|\.eot|\.svg|\.woff/,
        handler: 'fastest',
        options: {
            cache: {
                maxEntries: 10,
                name: 'fonts-cache'
            }
        }
    },
    {
        urlPattern: /^https:\/\/example\.com\/api/,
        handler: 'networkFirst',
        options: {
            cache: {
                maxEntries: 1000,
                name: 'api-cache'
            }
        }
    },
]

參考:https://lavas.baidu.com/pwa/offline-and-cache-loading/service-worker/service-worker-lifecycle
2017年2月25日 00:33