DarkGhostHunter
DarkGhostHunter

Reputation: 1550

Can I make a HTML5 updateable database to search locally?

I'm making a site with huge focus on index searching inside the site. The problem lies with the querys, as the production server is very cheap. I thought that could be a good idea to start with node.js instead of PHP for developing. But the problem lies far more ahead.

I want to push part (Name, Surname, Tags, URL) of the database of the site to the client browser and make a search locally, push live updates every time a new entry in the database is added by a user, and re-download everything after 24 hours more or less. That way the server doesn't work too much putting the results in the client, only pushing the new entries instead or the database.

Can I do that? What should I need? I thought about using IndexedDB and add a polyfill for WebSQL browsers, but I don't know if these technologies can do that I'm asking for today.

Upvotes: 1

Views: 359

Answers (1)

buley
buley

Reputation: 29208

IndexedDB is the perfect tool for this job, presuming the compatibility works for your customer base. While WebSQL would be an enviable alternative, know that for all intents and purposes the spec is "dead" and will not be developed further.

IDB is an "indexed" JavaScript object store, so you can add indexes on your object attributes and "cursor" across them without a huge performance overhead associated with trying to do this using something like localStorage. For example, say you have a customer list. You can add customer objects { 'name': 'blah', 'surname': 'McBlaherson', 'tags': [ 1, 2, 3] }, add some indexes and use IDB to, say, return all customers by surname.

The big challenge in what you're describing is handling the "sync" aspects of a client-server model. Say the user opens up the site on a browser and on his mobile phone. How do you merge the data stores? It sounds easy but I assure you it's not (which is why git and other version control systems are so magic).

Upvotes: 2

Related Questions