ios – 在WKWebView中”reload’与’reloadFromOrigin’

前端之家收集整理的这篇文章主要介绍了ios – 在WKWebView中”reload’与’reloadFromOrigin’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
WKWebView中reload和reloadFromOrigin之间的区别是什么? Apple的文档说reloadFromOrigin:

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

但我不确定这究竟意味着什么.

解决方法

我也对此感兴趣.看看WebKit的源(Source / WebCore / loader / FrameLoader.cpp,FrameLoader :: addExtraFieldsToRequest(…)围绕if(loadType == FrameLoadType :: Reload)条件)看起来关键区别在于什么额外的HTTP头请求字段已指定.

reloadFromOrigin()将Cache-Control和Pragma字段设置为no-cache,而简单的reload()仅导致设置max-age = 0的Cache-Control头字段.

为了解决这个问题,我查看了Header Field Definitions section of the HTTP 1.1 spec.第14.9.4节“缓存重新验证和重新加载控件”状态:

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,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中的两个函数的头文件/类参考文档相矛盾.我认为两者的描述应该交换 – 我已经向Apple提交了Bug Report / Radar 27020398,如果我听到的话会以任何一种方式更新这个答案从他们回来…)

原文链接:https://www.f2er.com/iOS/328946.html

猜你在找的iOS相关文章