小编lib*_*ked的帖子

为什么必须在服务工作者中克隆获取请求?

在Google的一个Service Worker示例中,缓存和返回请求

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }

        // IMPORTANT: Clone the request. A request is a stream and
        // can only be consumed once. Since we are consuming this
        // once by cache and once by the browser for fetch, we need
        // to clone the response.
        var fetchRequest = event.request.clone();

        return fetch(fetchRequest).then(
          function(response) {
            // Check if we received a valid response
            if(!response || …
Run Code Online (Sandbox Code Playgroud)

javascript service-worker

9
推荐指数
1
解决办法
1637
查看次数

标签 统计

javascript ×1

service-worker ×1