weixin_39612297
2021-01-12 19:42 阅读 1

Add remoteResources parameter to allow pre-caching third party remote resources

This allows people to pre-cache frameworks and external resources loaded remotely from CDNs like AngularJS from Google CDN or jQuery or others.

该提问来源于开源项目:GoogleChromeLabs/sw-precache

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • weixin_39600319 weixin_39600319 2021-01-12 19:42

    Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

    :memo: Please visit https://cla.developers.google.com/ to sign.

    Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.

    • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
    • If you signed the CLA as a corporation, please let us know the company's name.
    点赞 评论 复制链接分享
  • weixin_39600319 weixin_39600319 2021-01-12 19:42

    CLAs look good, thanks!

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 2021-01-12 19:42

    I appreciate the contribution, but I'm afraid that it's not something I'd want to merge into sw-precache.

    I'd like to keep sw-precache focused on versioning and caching local resources. The service worker it generates uses a cache-first strategy and relies on being able to calculate a hash of local resources to detect changes and ensure that users' caches are kept up to date.

    For a remote resource that can't be versioned by sw-precache, I'd recommend employing a runtime caching strategy, and the sw-toolbox library can help with that. You can see an example of using sw-precache and sw-toolbox together to handle both local and remote resources in the Web Starter Kit project: - sw-precache config - sw-toolbox config

    I understand that needing to cache both local and remote resources is a very common use case, and we're exploring approaches to make it easier to use and configure both sw-precache and sw-toolbox in a consistent manner. Stay tuned for that, likely in the next major release of sw-precache.

    点赞 评论 复制链接分享
  • weixin_39732716 weixin_39732716 2021-01-12 19:42

    we're exploring approaches to make it easier to use and configure both sw-precache and sw-toolbox in a consistent manner. Stay tuned for that, likely in the next major release of sw-precache.

    did that happen?

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 2021-01-12 19:42

    Yes! See https://github.com/GoogleChrome/sw-precache#runtime-caching

    点赞 评论 复制链接分享
  • weixin_39828457 weixin_39828457 2021-01-12 19:42

    i am in utter shock. I have been looking for a solution like this since the first PWA workshop i attended (organised by google team) that is, "How to pre-cache the CDN resources?". And there are at least 10 Stackoverflow questions seeking the same, and you guys are forwarding people to sw-toolbox. Sad :(

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 2021-01-12 19:42

    sw-precache and sw-toolbox are "sibling" projects, each with a different focus. sw-precache is going to remain focused on precaching local assets, and it's fairly easy to pull in sw-toolbox alongside sw-precache to handle remote resources, via something like:]

    js
    {
      // Other sw-precache options...
      runtimeCaching: [{
        urlPattern: /^https:\/\/my-cdn\.com\/,
        handler: 'cacheFirst'
      }]
    }
    

    That will cause all requests for remote assets on https://my-cdn.com/ to be cached and re-used after they're requested the first time. If you want to pre-populate the cache, you can do that by calling the Cache Storage API directly, but runtime caching will eventually pick it up for you.

    点赞 评论 复制链接分享
  • weixin_39728572 weixin_39728572 2021-01-12 19:42

    I wanted to ask something related to CDN. (If you prefer a separate bug/question, please reply back and I will do the needful).

    I am looking for a way to use swPrecache to load my own static PWA resources from a CDN instead of the same domain. So these are all the same files available locally (so swPrecache has the hash , etc), but what I want is for swPrecache to fetch this resource from a CDN host rather than from my own PWA domain. Hope that makes sense.

    Here is the related SO question from me: http://stackoverflow.com/questions/43754183/swprecache-and-cdn-as-proxy

    点赞 评论 复制链接分享

相关推荐