4

I am using a wkwebview to display a URL, I need the site data and cache to deleted or not to save cache at all. I need it to load up a fresh page each time. I have tried several methods but none work.

@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var searchBar: UISearchBar!

override func viewDidLoad() {
    super.viewDidLoad()

    searchBar.backgroundImage = UIImage() // removes border

    let myURL = URL(string: "https://myURL.com")!
    let myRequest = URLRequest(url: myURL)
    webView.load(myRequest)

}

}

  • Possible duplicate of [How to remove cache in WKWebview?](https://stackoverflow.com/questions/27105094/how-to-remove-cache-in-wkwebview) – Bilal Aug 24 '18 at 15:04

1 Answers1

8

If you don't ever want caching try setting the NSURLRequest.CachePolicy to reloadIgnoringLocalAndRemoteCacheData when initialising the URLRequest.

e.g.

let request = URLRequest(url: myURL, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 10)
veradiego31
  • 408
  • 5
  • 16
Gary M
  • 428
  • 5
  • 13