title: UIWebView - Issues while storing content for next launch
body: <p>I am saving the content of <code>UIWebView</code> so as to display it on the next launch rather than again loading it. This is what I am doing:</p>
  
  <pre><code>NSString *activityesContent = [webView stringByEvaluatingJavaScriptFromString:@"document.body.outerHTML"];
          [[NSUserDefaults standardUserDefaults]setObject:activityesContent forKey:@"activityesContent"];  
  </code></pre>
  
  <p>And for the next launch I am doing this:</p>
  
  <pre><code>[_tgWebView loadHTMLString:[[NSUserDefaults standardUserDefaults]objectForKey:@"activityesContent"] baseURL:nil];  
  </code></pre>
  
  <p>This loads the page but without any JavaScript or CSS. It is just a basic HTML content. I know I can load the JavaScript using <a href="http://iphoneincubator.com/blog/tag/stringbyevaluatingjavascriptfromstring" rel="nofollow noreferrer"><strong>stringByEvaluatingJavaScriptFromString</strong></a>. But is there somehow I can get all the JavaScript and CSS on the page as I am getting the HTML content, so that I can use it later on?</p>
  
  <p>I also tried with <code>document.body.parentNode.innerHTML</code> and <code>document.documentElement.outerHTML</code>, but still basic HTML is displayed. The reason for this is, the images, CSS and JavaScript has a server path. I have asked one more <a href="https://stackoverflow.com/questions/28499690/nsurlprotocol-handle-https-request">question</a> but it doesn't work for my HTTPS requests.</p>
  
  <p>Neither does this work:</p>
  
  <pre><code>NSError *error = nil;
          NSString *activitiesContent = [NSString stringWithContentsOfURL:[NSURL URLWithString:TGURL_ACTIVITIES] encoding:NSUTF8StringEncoding error:&amp;error];
  </code></pre>
  
  <p>I tried <a href="https://stackoverflow.com/questions/1343515/how-to-save-the-content-in-uiwebview-for-faster-loading-on-next-launch/2468722#2468722">this</a> solution which is being referred at most of the places. But this gives me a blank page. I even tried to save the contents in a file. When I accessed the source of the page in the file, I found that the path of CSS and JavaScript is relative:</p>
  
  <pre><code>&lt;link href="/Content/Sass/style_sass.css?version=1.0.1.09" rel="stylesheet" /&gt;  &lt;!-- call style_sass.css file --&gt;
      &lt;link href="/Content/Sass/topbar.css?version=1.0.1.09" rel="stylesheet" /&gt;  
  </code></pre>
  
  <p>If I try <a href="https://stackoverflow.com/questions/6420925/load-resources-from-relative-path-using-local-html-in-uiwebview">creating resource folder</a>, the size of this folder will be huge. Plus there will be a maintenance issue. I have to update the CSS/JavaScript each time there is a change in server CSS/JavaScript.   </p>
  
  <p>This is what I am getting:  </p>
  
  <p><img src="https://i.stack.imgur.com/vtEDZ.png" alt="enter image description here">  </p>
  
  <p>And this is what the page should be:</p>
  
  <p><img src="https://i.stack.imgur.com/Jl3IR.png" alt="enter image description here">  </p>
  
  <p><strong>Finally what I want:</strong></p>
  
  <p>What is the best fix for this or is there some other way I can show the entire page (including CSS, JavaScript, images) on the app's further launches ?</p>