What are iPhone Safari Databases?

February 14, 2010 / Updated: February 14, 2010 / Lena Shore
Filed under: ,

Question

Recently, I was poking around under my Safari Settings (Settings –> Safari) on my iPhone and came across an entry for databases. What are these?

Answer

iPhone Safari supports HTML 5’s client-side storage structure just as your desktop version of Safari (Safari –> Preferences –> Security –> Show Databases). It is useful for developing off-line capabilities for web-apps. They happen when you go to a website that has implemented the technology.

The idea is if you can store some information on your iPhone that you normally retrieve when visiting a website, your experience can be better/quicker.

Here is an example quoted from the W3:

…designed for scenarios where the user is carrying out a single transaction, but could be carrying out multiple transactions in different windows at the same time.

Cookies don’t really handle this case well. For example, a user could be buying plane tickets in two different windows, using the same site. If the site used cookies to keep track of which ticket the user was buying, then as the user clicked from page to page in both windows, the ticket currently being purchased would “leak” from one window to the other, potentially causing the user to buy two tickets for the same flight without really noticing.

To address this, this specification introduces the sessionStorage DOM attribute. Sites can add data to the session storage, and it will be accessible to any page from the same site opened in that window.

For example, a page could have a checkbox that the user ticks to indicate that he wants insurance… A later page could then check, from script, whether the user had checked the checkbox or not.

If the user had multiple windows opened on the site, each one would have its own individual copy of the session storage object.

The second storage mechanism is designed for storage that spans multiple windows, and lasts beyond the current session. In particular, Web applications may wish to store megabytes of user data, such as entire user-authored documents or a user’s mailbox, on the client side for performance reasons.

Again, cookies do not handle this case well, because they are transmitted with every request.

If you want all the really gory technical stuff, you can read about it here.

While all major browsers (except for Microsoft Internet Explorer) seem to support much of what HTML5 has to offer currently — the World Wide Web Consortium (W3.org) has not reached a recommendation on using it yet. It is expected to be recommended by late 2010. I imagine at that point you will see a lot more usage of the databases. However, since the iPhone only has one browser to contend with, it is easy for iPhone developers to make the decision to take advantage of those databases. Complete implentation of HTML5 for the Word Wide Web won’t happen for years though – so don’t hold your breath while you wait.

Update

I have been getting tons of email asking various questions about the security of Safari Databases. You can see some of the questions in the comments. Everyone seems to be paranoid about them and are scared they are some rogue attempt to send information to 3rd parties. This is not the case. It’s just a way for information you have already supplied to a website to be stored on your iPhone so if you ever go back to that website it will be available and improve your user experience. Feel free to delete them with abandon if they make you nervous. But, they shouldn’t. I encourage you to read through some of the documentation here if you are still nervous. Once you understand, you won’t be.

Archives

Categories