title: JavaScript save blob to localStorage
body: <p>I am trying to save <code>blob</code> data (favicon) retrieved via AJAX, to <code>localStorage</code>.</p>
  
  <p><strong>Code :</strong></p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open('GET', 
  'http://g.etfv.co/http://www.google.com',
  true);
  xhr.responseType = "blob";
  xhr.onload = function(e){ //Stringify blob...
      localStorage['icon'] = JSON.stringify(xhr.response);
      //reload the icon from storage
      var fr = new FileReader();
      fr.onload = 
          function(e) {
              document.getElementById("myicon").src = fr.result;
          }
      fr.readAsDataURL(JSON.parse(localStorage['icon']));
      }
  xhr.send(null);
  </code></pre>
  
  <p>The code is adapted from <a href="https://stackoverflow.com/a/20724019/1433559">here</a> with minor modifications to make it work with <code>localStorage</code>.
  localStorage saves all data as strings, so blobs need to be <strong>stringified</strong> somehow before being saved.</p>
  
  <p><code>JSON</code> doesn't deal with blobs as one of it's supported types, so it's no surprise that this code fails.</p>
  
  <p>Is there any way to get the blob into localStorage?</p>