简体   繁体   中英

Can I use a database in the browser?

My application needs to use a database. I've read online that databases are supported in some browsers but they are now deprecated? It was very confusing. I need to use a database with HTML. Is it possible to use a database with HTML5?

UPDATE
It needs a database to store data when the user is offline. It needs to support the major browsers from IE 9 on up if possible on Mac and Win on desktop and possibly Linux. The application is a client side HTML editor. There is no server side yet. So I need to persistently store "files" on the client side. Also, when I do have a server side I still need to save the users work when they have no internet connection. Later, when they go online the application can sync up with the server side. I could make do with Local storage but it is too limited in space at 5MB. That's the maximum limit? The application allows you to use images and those will be saved to base 64 data URI resources so you will quickly use up that space with just a few projects.

A few people asked why go for a database on the client. Because it's appropriate for this situation and if browsers support it then I would like to use it.

You should not use a database in the browser, even if you could, because that probably is not standard conforming. However perhaps consider HTML5 local storage

What you can is develop some web service accessing a database; that access happens in the HTTP server (so the database is used in the server, not in the browser, which just indirectly gives access to it).

I would suggest to develop your web application in Opa but you could even use PHP for that. And you could make it a CGI or a FastCGI application.

BTW; you did not tell us which operating system you are using.

You could consider making your application some specialized HTTP server, eg using Wt or Ocsigen -or using some HTTP server library like libonion etc- and then it could access some database (and your application could run on eg localhost:8086 if you wanted to).

PS. I believe that having some web pages storing a large amount of data on the client side (in the browser) is simply not reasonable (and against the standard and the spirit of the web). You should store such large data on the server side (or have some URL to download it from the server). You could decide to make a "server" application running on localhost (of course, this is operating system specific).

PPS: If coding an HTML editor, I am not sure that standard browsers are the adequate tool. You may however use the contenteditable attribute.

Check in CanIUse website.

http://caniuse.com/#feat=sql-storage

It's not DEPRECATED, but it's not supported by all browsers so far. The reason is that it did not become a valid standard because all the approaches are based in SQLite, and this is way too limited to be considered a standard.

yes go for indexedDB. Its still in development phase but you can use it

http://www.html5rocks.com/en/tutorials/indexeddb/todo/

I've read online that databases are supported in some browsers but they are now deprecated?

You're right: The Web SQL Database spec has been abandoned. There are a few browsers that still support it, but not many, and it will likely disappear entirely in the very near future.

As an alternative, a newer spec called IndexedDB is now being promoted by the browser vendors. The down-side is that it is still relatively new, and thus you will probably have many users with have browsers that do not support it.

Depending on the size of the data you need to store, you might consider Web Storage instead. This is intended just for plain text, and can't store massive quantites of data, but it is a well-established standard, so you've got a much better chance of compatibility.

If you can get away with storing a relatively small data set (ie a few megabytes or less) then this is definitely the best option here. This would certainly be my advice; try to keep your offline data requirements as small as possible, and keep them in Web Storage.

Hope that helps.

For a detailed run-down of all available browser-side storage options, you should read this article . It gives a much more detailed description of each of the options I described above, plus a few others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM