title: is it possible to preload html before displaying on webview
body: <p>I have searched whole internet and couldn't find the solution so decided to ask expert that is it even possible.</p>
  
  <p>I have a Blog for which I am developing iOS app but it takes too much time loading the content. </p>
  
  <p>So is it possible to pre load html (not images) of all articles before user opens the article, just like FB instant articles. FB instant articles are preloaded and cached and when user opens it then it opens in a flash except images, which download when user opens it.</p>
  
  <p>Currently I am using uiwebview which I am planing to replace with wkwebview.</p>
  
  <p>Thanks for help in advance.</p>
  
  <p>call to cache </p>
  
  <pre><code>CachedArticles.shared.cacheArticles(self.articles) { success 
      print("cache creation finished, success: \(success)")
  }
  </code></pre>
  
  <p>call to webview</p>
  
  <pre><code>tableView.deselectRow(at: indexPath, animated: true)
  let webVC = storyboard!.instantiateViewController(withIdentifier:"NewsReaderViewController") as! NewsReaderViewController
  webVC.article = self.articles?[indexPath.row]
  navigationController?.pushViewController(webVC, animated: true)
  </code></pre>
  
  <p>cache class</p>
  
  <pre><code>import UIKit
  
  class CachedArticles: NSObject {
  
  static let shared: CachedArticles = CachedArticles()
  
  let cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
  
  func cacheArticles(_ articles: [ArticalClass]?, completion: @escaping (Bool)-&gt;() ) {
  
      guard let articles = articles else { return }
  
      DispatchQueue.global().async {
          DispatchQueue.main.async {
              UIApplication.shared.isNetworkActivityIndicatorVisible = true
          }
  
          var success = true
  
          for article in articles {
              guard let path = article.url, let url = URL(string: path), self.webArchive(forHeadline: article.headline!.replacingOccurrences(of: " ", with: "")) == nil else { continue }
  
              print("caching article: \(article)")
              do {
                  let data = try Data(contentsOf: url)
                  let url = self.cacheFileURL(forHeadline: article.headline!)
                  STWebArchiver().archiveHTMLData(data, textEncoding: "UTF-8", baseURL: url, completionBlock: { data in
                      (data! as NSData).write(toFile: url.path, atomically: true)
                  })
              } catch let error {
                  success = false
                  print("Error: \(error)")
              }
          }
  
          DispatchQueue.main.async {
              UIApplication.shared.isNetworkActivityIndicatorVisible = false
              completion(success)
          }
      }
  }
  
  func webArchive(forHeadline: String?) -&gt; URL? {
      let url = cacheFileURL(forHeadline: forHeadline!)
      return FileManager.default.fileExists(atPath: url.path) ? url : nil
  }
  
  private func cacheFileURL(forHeadline: String) -&gt; URL {
      let url = URL(fileURLWithPath: self.cachePath).appendingPathComponent(forHeadline.replacingOccurrences(of: " ", with: "")+".webarchive")
      return url
  }
  
  }
  </code></pre>