'reload' 与 WKWebView 中的 'reloadFromOrigin'

'reload' vs 'reloadFromOrigin' in WKWebView

WKWebView中的reloadreloadFromOrigin有什么区别?苹果的文档说 reloadFromOrigin:

Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.

但我不确定这到底是什么意思。

我也对这个很感兴趣。查看 WebKit 的源代码(Source/WebCore/loader/FrameLoader.cppFrameLoader::addExtraFieldsToRequest(...) 围绕 if (loadType == FrameLoadType::Reload) 条件),看起来主要区别在于指定了哪些额外的 HTTP header 请求字段。

reloadFromOrigin()Cache-ControlPragma 字段设置为 no-cache,而简单的 reload() 只会导致 Cache-Control header 字段设置了 max-age=0

为了弄清楚这意味着什么,我查看了 Header Field Definitions section of the HTTP 1.1 spec。第 14.9.4 节 'Cache Revalidation and Reload Controls' 指出:

The client can specify these three kinds of action using Cache- Control request directives:

End-to-end reload The request includes a "no-cache" cache-control directive or, for compatibility with HTTP/1.0 clients, "Pragma: no-cache". Field names MUST NOT be included with the no-cache directive in a request. The server MUST NOT use a cached copy when responding to such a request.

Specific end-to-end revalidation The request includes a "max-age=0" cache-control directive, which forces each cache along the path to the origin server to revalidate its own entry, if any, with the next cache or server. The initial request includes a cache-validating conditional with the client's current validator.

Unspecified end-to-end revalidation The request includes "max-age=0" cache-control directive, which forces each cache along the path to the origin server to revalidate its own entry, if any, with the next cache or server. The initial request does not include a cache-validating conditional; the first cache along the path (if any) that holds a cache entry for this resource includes a cache-validating conditional with its current validator.

根据我对规范的阅读,看起来 reload() 仅使用 max-age=0,因此可能会导致您获得请求数据的缓存但经过验证的副本,而 reloadFromOrigin() 将强制从原始服务器获取新副本。

(这似乎与 Apple 对 WKWebView 中两个函数的 header/Class 参考文档相矛盾。我认为对这两个函数的描述应该互换 - 我已经向 Apple 提交了 Bug Report/Radar 27020398 并且如果我收到他们的回复,我会以任何一种方式更新这个答案...)