Cacheing a webview from a non-local url
I have a webview that is populated by a remote (non-local) url. The webpage is pretty simple, it's basically just a set of images.
I'd like to be able to tell if the remote website is down, to trigger the use of the local version in its place. The best I've come up with is to wait N seconds to hear an event fired from the webview.
I know how to save the images to the Filesystem, so I think I can reasonably recreate the webview from local data like this. I would probably literally inject the file URLs into the html template as a giant string.
Cacheing the entire webview's contents (html and images) to a file as a blob would also be nice, but that seems difficult…
In summary, handling a remote webview that is down seems like it will be a common problem, so I am wondering if there is a "right", or at least better, way to handle it. Thanks!
3 Answers
-
to see if a site is down etc, you could always use the 'this.status' response from an XHR onreadystatechange to look for a 404 (or whatever http status might let you r know something's down/up.
eg:
if(this.status=='404'){ // your code }
-
Good suggestion. Thanks!
-
Kosso, your code is very helpful (and I'll be using it), however there is still the remainder of the problem: if, for example, the user downloads an article and wants to read it without a connection later, it'd be nice to grab it from the cache