2

Is it possible to use a local database file with html5 without using a server. I would like to create a small application that depends on information from a small database. I do not want to host a server just to pull information. Is it possible to create a database file and pull information from the local files ?

Mogsdad
45.9k21 gold badges165 silver badges287 bronze badges
asked Dec 2, 2013 at 23:12

3 Answers 3

2

Depends on the following:

The type of application you want to build:

  • Normal website with some data being pulled from a local storage;
  • Special purpose hosted website / application with data generated by the user;
  • Special purpose local application with a dedicated platform (a particular browser) and with access to the browser's non-web API -- in order to access the browser's own persistent storage methods (file storage, SQLite etc.);
  • Special purpose local application with a dedicated environment -- in order to deploy the application with a local web server and database;

Available options:

  • Indexed DB
  • Web Storage
  • XML files used for storing data and XSLT stylesheets for translating the data into HTML;

Indexed DB and Web Storage ar available in some browsers but you need to make sure the targeted browsers have it. Their features aren't quite as complete and flexible as SQL RDBMSs but they may fit the bill if your application doesn't need all that flexibility.

XML files can contain the data you want to be shown to the user and they can be updated manually (not by the user) or dynamically (by a server script). For dynamic updating the content of the XML is kept in JavaScript and manipulated / altered (using the XML DOM) and when the session is over the XML content is sent to the server to entirely replace the previous XML file. This works OK if the individual users have a file each and they never write to each other's files.

Reading local files:

Normal file access is prohibited (for security reasons) to all local (JavaScript) code, which means that "having" a file locally implies either downloading it from a known source (a server) or asking the user to offer access to a local file.

Asking the user to offer access to a local file which implies offering the user a "file input" -- like for uploads but without actually uploading the file.

After a file has been selected using FileAPI to read that file should be fairly simple.

This workflow would involve the user "giving" you the database on every page refresh -- but since it's a one page thing it would mean giving you the data on every session as long as your script does not refresh the page.

answered Dec 2, 2013 at 23:14

Comments

1

What i'm looking for is a little more robust than a cookie. I am making a web application for a friend that will be 1 page, and have a list of names on the page. The person wants to be able to add names to the list, however they do not want to use a web server. Just want the files locally on a computer so a folder called test-app , with index.html, and possibly a database file that can be stored in the web browser or a way to save information to the web browser for repeated use.

answered Dec 2, 2013 at 23:17

2 Comments

Normal file access is prohibited (for security reasons) to all local (JavaScript) code. "having" a file locally means either downloading it from a known source (a server) or asking the user to offer access to a local file (such as a browse-for-upload button) and then using the newer FileAPI / FileReference to read that file.
As I've added to my answer you're not going to get too far with file access unless you can make some serious concessions. The Indexed DB and Web Storage alternatives are a better fit for your needs. They were designed exactly for replacing cookie/session functionality.
1

You can use localstorage but you can run a server from your own computer. You can use Wamp or Xampp. Which use Apache and mysql.

answered Dec 2, 2013 at 23:18

1 Comment

Or a portable PHP executable (i recall that as of v.5.4 PHP has its own small web server for testing purposes) with SQLite as a database backend.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.