簡體   English   中英

sw precache-從不同域加載資產的運行時緩存

[英]sw precache - runtime caching for assets loading from different domain

我正在使用sw precache管理我的服務人員。 假設我的網站是abc.com,服務工作者正在此網站上運行並由url abc.com/service-worker.js加載

為了優化目的,從不同的URL加載了所有的CSS和JS,讓我們說xyz.com

現在在運行時緩存中,當我提供

{
  // See https://github.com/GoogleChrome/sw-toolbox#methods
  urlPattern: '*.css',
  handler: 'fastest',
  // See https://github.com/GoogleChrome/sw-toolbox#options
  options: {
    cache: {
      maxEntries: 20,
      name: 'css-cache'
    }
  }
}

這僅從URL abc.com/style/style.css緩存CSS,而不從xyz.com/style/test.css緩存CSS

我努力了

{
  // See https://github.com/GoogleChrome/sw-toolbox#methods
  urlPattern: 'https:\/\/xyz\.com\/*.js',
  handler: 'fastest',
  // See https://github.com/GoogleChrome/sw-toolbox#options
  options: {
    cache: {
      maxEntries: 20,
      name: 'js-cache'
    },
    // urlPattern: /\.googleapis\.com\//,
  }
}

但都是徒勞的。 如果有人遇到過同樣的問題,那么朝着正確方向的任何幫助將不勝感激。

我相信您的問題是,您實際上應該傳遞正則表達式時將字符串作為urlPattern傳遞。

因此,您應該使用/https:\\/\\/xyz\\.com\\/*.js/而不是'https:\\/\\/xyz\\.com\\/*.js' /https:\\/\\/xyz\\.com\\/*.js/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM