Caching external resources using sw-precache

I am trying to get sw-precacheto pre-cache external CDN resources, but the generated service-worker.js does not contain the CDN URL in the array precacheConfig.

This is what I have in my gulpfile:

staticFileGlobs: [
    'http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css',
     'client/assets/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff,ico}'
]

Files in the local local folder client/assetsare added to the array precacheConfig, but the cs awesome external font is not. Is there any way to achieve this?

+4
source share
1 answer

sw-precache , , client/assets/**/*..., . , CDN.

:

  • npm ( ), (.. font-awesome), . , staticFileGlobs, , .

  • CDN. URL- 4.0.3, , , cacheFirst, , .

sw-precache, :

{
  staticFileGlobs: [
    'client/assets/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff,ico}'
  ],
  runtimeCaching: [{
    urlPattern: /^https:\/\/netdna\.bootstrapcdn\.com\//,
    handler: 'cacheFirst'
  }],
  // ...any other config options...
}

, , CDN, , .

, http: URL- CDN, https: , -.

+8

Source: https://habr.com/ru/post/1660680/


All Articles