Search code examples
iosswiftxcodewkwebviewsfsafariviewcontroller

How to load a website faster with SfSafariView or WKWebView using cache?


I have used SFSafariView to load a ‘HTTPS’ website but its taking way to long to load up each time upon button click. I remember when using the UiWebView a few years back on a tabbed application it would load the website first time when you get onto the web view controller but after the first load the load on that web view would be instant. Is there any way to load a website before bringing up that view or a way to load it on the first time but after that time it loads faster (using cache) ?

I have tried looking for tutorials and information online and have tried using the WKWebView and playing around with the SFSafariView, cannot find anything specific to functionality I would like. Any Help would be greatly appreciated.


Solution

  • Try use cache policy.

    let urlRequest = URLRequest(url: URL(string: "www.example.com")!, cachePolicy: .reloadRevalidatingCacheData, timeoutInterval: 15.0)
    let wkWebView = WKWebView(frame: .zero)
    wkWebView.load(urlRequest)