WKWebView is perfect for web request interception. Recently, WKWebView has had time for caching. The source code to see SSWKURL

The cache

Implementation is relatively simple, is the memory and disk IO level cache. Policies can be freely controlled. POST requests are usually not cached, Ajax is not cached, videos are not cached

    BOOL shouldCache = YES;
    if(request.HTTPMethod && ! [request.HTTPMethod.uppercaseString isEqualToString:@"GET"]) {
        shouldCache = NO;
    }
    NSString *hasAjax = [request valueForHTTPHeaderField:@"X-Requested-With"];
    if(hasAjax ! =nil) {
        shouldCache = NO;
    }

Copy the code

Cache performance

The bilibili single page test finished loading about 4 ~ 5 seconds before caching. About 0.8-1 seconds after caching. Performance is similar to WebView’s own HTTP caching strategy. Small performance difference can greatly improve the performance of the first screen loading. There is still room for further optimization.

Contrast vassonic

Advantage:

  • Using WKWebview(main difference)
  • A lightweight

Disadvantage:

  • Does not support static and static separation (requires web page reconstruction, meaning limited)
  • IOS13 or later is not supported