且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是不透明响应,它的用途是什么?

更新时间:2021-11-29 03:54:30

考虑 Service Worker 充当不可知缓存的情况.您唯一的目标是提供与您从网络获得的资源相同的资源,但速度更快.当然,您不能确保所有资源都属于您的来源(例如,考虑从 CDN 提供的库).由于 service worker 有可能改变网络响应,你需要保证你对响应的内容不感兴趣,也不关心它的头部,甚至不关心结果.您只对作为黑盒的响应感兴趣,以便可能缓存它并更快地提供它.

Consider the case in which a service worker acts as an agnostic cache. Your only goal is serve the same resources that you would get from the network, but faster. Of course you can't ensure all the resources will be part of your origin (consider libraries served from CDNs, for instance). As the service worker has the potential of altering network responses, you need to guarantee you are not interested in the contents of the response, nor on its headers, nor even on the result. You're only interested on the response as a black box to possibly cache it and serve it faster.

这就是 { mode: 'no-cors' } 的用途.