1 Reply Latest reply on Mar 3, 2008 6:11 AM by blaike

    iframe cache

    Ahmettaha
      Hello,
      I'm very new to AIR, and I wonder if the following is possible. I have a website, and I want this website to be viewed with an AIR application. I can access the website via iframe, no problem. My goal is to store some data from the website to be viewed later by the user when they are offline. Like for example, in the news section. When the user is online, I want it to connect to the website and show the content. However, when the user is offline, I want it to show everything the same, and when user clicks on the page link for news, AIR should know it's offline, and show the locally stored data. Is this possible?

      Or do I have to create a complete seperate user interface for AIR. I'm wondering if it's possible to use iframe when online, and load everything locally when offline.

      Thanks,
      ahmet
        • 1. Re: iframe cache
          blaike
          There are many ways to approach this particular problem.. These are my takes on this.

          First, I don't think you'll need to create a separate interface for the air application. You can use your current interface if you want, and I guess it would save you a lot of time on building a separate interface.

          Since you'll be loading external content, you'll need to use two sandboxes: the main application sandbox and the non-application (iframe) sandbox--but I guess you already know that. You'll have to use these two separate (albeit connected) sandboxes to your advantage.

          The algorithm goes something like this: When the user starts the application, the main application sandbox should check whether or not the user is connected to the internet (via the URLMonitor subclass of the ServiceMonitor Class). If the user is online, then it will proceed and trigger an event (or function) from the non-application sandbox that will tell it to load the content from the external website. When the content is loaded, the app should then perform a silent caching of the loaded data, storing it on the local computer. If the user is offline, then the app should load cached local data instead or if there is no cached data, then a helpful dummy page should then be loaded.

          You can then monitor the events in the non-application sandbox. If the user is online and tries to click a link, then proceed with the normal functions and routine loading. If the user is offline, then the application should then cancel the event and proceed with any functions that handle loading cached pages or showing error (non-connectivity) messages.

          This approach works well in the sense that you almost won't have to change any code on your website. All of the event handling, monitoring and checking will be done by the air application and the code in the application sandbox. Which means you can use the code on your website as it is without any further changes.

          The cons of this approach it that you'll probably spend a lot of time in fine-tuning your application sandbox code to handle certain events. But when you actually get the basic code, it's almost smooth sailing from there.

          The other approach I can suggest is that you'll use the non-application sandbox code to detect whether the user is using a regular browser or the air app in loading the website. After detecting this, you can use separate functions to handle loading pages depending on whether or not the user is offline. For instance, after determining that the user is using an air app, a function in the non-application sandbox can then ping the application sandbox (via a script through the sandbox-bridge) to see if the app is online. If it is, then you can proceed with normal loading. If not, you can then again access another function via the sandbox bridge to load content from the catch.

          Hope this helps!