Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked March 16th 2010 by Brian Naughton
  • filesystem
  • html
  • url
  • webview
0 Comments

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
    
    }
    
    — answered March 16th 2010 by Kosso
    permalink
    0 Comments
  • Good suggestion. Thanks!

    — answered March 16th 2010 by Brian Naughton
    permalink
    0 Comments
  • 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

    — answered April 27th 2010 by Will Collins
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.