Signup for the Ionic Newsletter to get the latest news and updates!

  • Young Park

    if it’s just a simple cache that’s needed, i’d better use PouchDB.

  • Sergio Milici

    How do you use service workers on a cordova app if they only run over https and not under file:// protocol?

    • Drew Rygh

      I think you’ve answered your own question — you don’t 🙂

      There is a workaround on iOS, and a plugin, but AFAIK there is no way to use service workers in an Android WebView right now. I’d imagine this will change eventually.

      Plenty of other ways to add offline support though 🙂

      • Sergio Milici

        Yes, i found that plugin. Thanks.
        I was more interested in offline support with sync capabilities. Just keeping the data locally are many options to do that, for for syncing not. Maybe firebase but on web still is not 100% real offline. Maybe couchdb too, but you have to have a server to sync with and there are not too many paas that offers that. i’m working with crdt but it’s a real different scenario. I want 100% offline support and sync without special tricks.

        Great article and thanks for the response.
        if you have any thoughts about this, i would like to continue talking with you.

        • jerome

          I use a ‘homemade’ solution with cordova content-sync. But for that i use Json persistence with the cordova file plugin not sqlStorage.
          On the server side I have a service that ‘transforms’ the parts i need from my MYSQL data into a downloadable zip File containing a JSON file and referenced images/files). This is important for cordova-content-sync : it works with a download link and zip files only. If you need to constantly check for sync (..and you don’t have any heavy stuffs you need to sync )use a simple REST API.

          One you have your JSON you can do pretty powerful stuff with lokiJs/underscore etc. if you need good optimization/performance. I did some test with LokiJs and it’s quite great 🙂 but for my app I didn’t need that kind of stuff, just a simple json and underscore.

          you just have to create an algorithm that would define when you need to sync (I use a last_updated_at attribute) sent via a rest api, if the last_updated at is different from the local last_updated_at i download the zip file and cordova-content-sync replaces my files.

          I know pouchDb/firebase have powerful sync abilities but in my case I had a MySQL database and I had to adapt to that :).

        • Jose

          I’m working on a mobile app that needs to support offline mode in case of rough internet connectivity and sync the data with a RestFull API every time that the internet is up and I still running into a few issues to sync the data. I didn’t find any good thoughts or ideas on how to manage synchronization in real time, if you have gotten any ideas or is interested in go deeper to figure it out, please send me a message.

        • Sampath Lokuge
  • Graphefruit

    Any conclusion about image/file caching and not just data?

  • http://www.raymondcamdencom/ Raymond Camden

    Small nit:
    “We’ll also need to add Ionic’s SQLite and Geolocation plugins:”
    Those aren’t by Ionic, right?

    • Drew Rygh

      You’re right, I’ll fix that up, thanks!

  • Rolf Erikson

    I cannot clone but get this instead:
    C:UsersRolfIonicionic-egna>git clone [email protected]:drewrygh/ionic-offline-demo.git
    Cloning into ‘ionic-offline-demo’…
    Warning: Permanently added the RSA host key for IP address ‘’ to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.

  • KingOfMyRoom = new Storage(SqlStorage);

    This first line gives me a promise error, I am not able to use SqlStorage

    EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./HomePage class HomePage_Host – inline template:0:0
    ORIGINAL EXCEPTION: TypeError: win.openDatabase is not a function

  • Yuri Camara

    And about PouchDB?

    • Jose

      as far I’m aware you have to have a couchDB in the backend to be able to use pouchDB.

      Can PouchDB sync with MongoDB/MySQL/my current non-CouchDB database?
      No, your backend needs to speak the CouchDB replication protocol. The magic of PouchDB CouchDB sync comes from this design, which in particular requires all documents to be versioned with the _rev marker. This allows PouchDB and CouchDB to elegantly handle conflicts, among other benefits.

  • disqus_9pSTO2tt0E

    Weather can change so how will you know the forcast in local database isn’t out of date?

  • Fabricio Avancini

    I get this error: “Supplied parameters do not match any signature of call target” at the line “ = new SQLite();”. Anyone knows what may be happening?

  • Muhammad

    How would SqlStorage work with JSON or NoSql? Say the model is far bigger than simple weather data, how do we go about storing it this way? Whats the best practice?

  • Nitish kumar Sharma

    how can save server images in database and shows on when internet is close and app is working on offline mode ?

    • aqm

      Use Base64 or a Bytes Blob

  • Simone Dagli Orti

    The new commands to add the plugins are:

    ionic cordova plugin add cordova-sqlite-storage
    ionic cordova plugin add cordova-plugin-geolocation

  • mel

    please am looking for how to synchronize mysql database and localstorage. i want users to access data when the app is offline truth the localstorage and when they are online, the localstorage update his data form mysql database. please need help