Ryan Watts
Ryan Watts

Reputation: 641

HTML5 Database Use without Server

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 ?

Upvotes: 2

Views: 7816

Answers (3)

Mihai Stancu
Mihai Stancu

Reputation: 16117

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.

Upvotes: 2

user1781498
user1781498

Reputation:

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.

Upvotes: 1

Ryan Watts
Ryan Watts

Reputation: 641

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.

Upvotes: 1

Related Questions