javascript - WKWebView loads HTML content too slowly in iOS9 using swift -


i have been trying integrate wkwebview subview of webview in uiviewcontroller. i've been able load content , communicate swift , javascript. however, loading time of html content without data manipulation takes close 2 seconds.

i have tested loading wkwebview empty body of html without scripts loading. still takes 600 milliseconds load.

the time taken difference between viewdidload , webview(webview: wkwebview, didfinishnavigation navigation: wknavigation!) 600 ms, if html contains empty body.

viewdidload function of viewcontroller

override func viewdidload() {     nslog("started - %@.%@", string(self.dynamictype), __function__)     super.viewdidload()      let wkconfiguration: wkwebviewconfiguration = wkwebviewconfiguration()     let usercontroller: wkusercontentcontroller = wkusercontentcontroller()     wkconfiguration.usercontentcontroller = usercontroller     wkconfiguration.processpool = vcwkwebview.wkprocess     self.wkwebview = vcwkwebview(frame: self.webview.bounds,configuration: wkconfiguration)     if let wkwebview = self.wkwebview {         self.webview.addsubview(wkwebview)         wkwebview.translatesautoresizingmaskintoconstraints = false         let height = nslayoutconstraint(item: wkwebview, attribute: .height, relatedby: .equal, toitem: self.webview, attribute: .height, multiplier: 1, constant: 0)         let width = nslayoutconstraint(item: wkwebview, attribute: .width, relatedby: .equal, toitem: self.webview, attribute: .width, multiplier: 1, constant: 0)         webview.addconstraints([height, width])         //wkwebview.delegate = self         wkwebview.navigationdelegate = self         wkwebview.loadcontent()     }      nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillshow:", name: uikeyboardwillshownotification, object: nil)     nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillhide:", name: uikeyboardwillhidenotification, object: nil)      nslog("ended - %@.%@", string(self.dynamictype), __function__) } 

vcwkwebview class :

class vcwkwebview: wkwebview  {      static let wkprocess: wkprocesspool = wkprocesspool()      private static let _url: nsurl = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("index", oftype: "html",indirectory:"www")!)      private static let _accessurl: nsurl = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("www", oftype: nil)!)       func loadcontent(){         nslog("started - %@.%@", string(self.dynamictype), __function__)         if #available(ios 9.0, *) {             self.loadfileurl(vcwkwebview._url, allowingreadaccesstourl: vcwkwebview._accessurl)         } else {             // fallback on earlier versions         }         nslog("ended - %@.%@", string(self.dynamictype), __function__)     }      override init(frame: cgrect, configuration: wkwebviewconfiguration) {         super.init(frame:frame, configuration:configuration)     }      convenience init(frame: cgrect){         let wkconfiguration: wkwebviewconfiguration = wkwebviewconfiguration()         self.init(frame:frame,configuration:wkconfiguration)     }      deinit{         print("deinit of vcwkwebview called")     } } 

could please me integrate wkwebview content loads faster?


Comments