fetch

作者: 高静最近在长脑子 | 来源:发表于2017-07-20 18:40 被阅读11次

    Fetch API 是基于Promise 设计

    mode 是 Service Worker 实现中最重要的参数,它的值可能是:

    cors: 采用跨域资源共享的方式去获取。要求对方服务器启用了 CORS 响应头,可以读取响应内容。否则会跨域失败。
    no-cors:采用非跨域资源共享的方式去获取。不要求对方的 CORS 设置,不可读取响应内容。
    same-origin:采用同域的方式去获取,如果 URL 跨域就会失败。

    cache: 缓存模式,可取: default, no-store, reload, no-cache, force-cache, only-if-cached。

    "default" Fetch will inspect the HTTP cache on the way to the network. If there is a fresh response it will be used. If there is a stale response a conditional request will be created, and a normal request otherwise. It then updates the HTTP cache with the response. [HTTP]

    "no-store" Fetch behaves as if there is no HTTP cache at all.

    "reload" Fetch behaves as if there is no HTTP cache on the way to the network. Ergo, it creates a normal request and updates the HTTP cache with the response.

    "no-cache" Fetch creates a conditional request if there is a response in the HTTP cache and a normal request otherwise. It then updates the HTTP cache with the response.

    "force-cache" Fetch uses any response in the HTTP cache matching the request, not paying attention to staleness. If there was no response, it creates a normal request updates the HTTP cache with the response.

    相关文章

      网友评论

          本文标题:fetch

          本文链接:https://www.haomeiwen.com/subject/fnxjkxtx.html