2

I have a website which has a lot of combo boxes and auto-complete textboxes, that take in data from the database masters.

I don't want the data to be loaded each time a user enter logs in, or the page refreshes.

What would be the most efficient and secure and fastest method to load and store data for the client.Also consider a medium sized database.

I tried a few things like,

  1. Storing in a Javascript array- Its lost once the user refreshes.
  2. Including Servlets to load data and fill in on the page, that too has same problem with refreshing.
  3. Using ajax and filling when ever required.
  4. Storing the data on server side by loading it once,this saves me the querying the database everytime. But with every logout/login it has to be maintained.

Is there a method better than this

P.S. Try not to make this too subjective, Please reply only the methods with a brief description of it.

Sangeet Menon
  • 9,555
  • 8
  • 40
  • 58
  • What problem are you actually trying to solve by avoiding database queries? – Christian Jun 20 '12 at 05:47
  • I trying to reduce the delay created due to fetching and loading the data to the page while website page loads. Querying everytime takes longer for me to load the the page. – Sangeet Menon Jun 20 '12 at 05:51
  • 1
    Your application data has to be stored/maintained at server side, which should be transferred to client side for displaying, whenever the client requests it. The data in server side, can be cached(to say `memcached`), so that you don't hit database for every request. – Chandra Jun 20 '12 at 06:04

4 Answers4

1

You should consider using HTML5 local storage.

Here's a demo!

And a tutorial.

Viren Rajput
  • 5,426
  • 5
  • 30
  • 41
  • html local storage stores data in the browser and it will be available even after you have logged out of your webpage. Isn't that a security concern? All your data in the client browser ? – Akhi Jun 20 '12 at 05:53
  • Dont think so, since the data that will be stored will be users data in his/her browser. – Viren Rajput Jun 20 '12 at 05:59
  • @Virendra does this load the entire combo-box data or does it only allow to store in the key-value format. I am looking for a method that has the entire combo-box data withing it. – Sangeet Menon Jun 20 '12 at 05:59
  • 1
    You can store any object in Web Storage, as long as you can stringify it. – Viren Rajput Jun 20 '12 at 06:04
  • If the data is sensitive(in this case looks like it as OP mentions user login), then HTML5 local storage is not a good idea. There is good explanation in [HTML5 localStorage security](http://stackoverflow.com/questions/3718349/html5-localstorage-security) – Chandra Jun 20 '12 at 06:08
  • @Chandra: No I am not intending to store sensitive data. Its like the combo-box of list of the institutions/services etc. – Sangeet Menon Jun 20 '12 at 07:06
  • @VirendraRajput How long does the browser hold the data and what is its scope? – Sangeet Menon Jun 20 '12 at 07:07
  • The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year. – Viren Rajput Jun 20 '12 at 07:09
  • and you can clear it anytime you want by using this "localStorage.clear();" – Viren Rajput Jun 20 '12 at 07:13
1

HTML5 local storage should work fine for you, however, if you like this to work across older browsers that do not support HTML5 take a look at: http://code.google.com/p/sessionstorage/

I have used it before in different applications and it works great. Also, why not use good old cookies?

ama2
  • 2,611
  • 3
  • 20
  • 28
0

It also depend on your setup that queries and loads the data. ASP.NET has some very good built in caching which can be set so avoiding the whole issue.

Ultimately, in anyone given project I find I use a few different options;
from page caching (so the server caches the page output),
to using session cookies to hold certain data which can be carried around the site,
to persistant cookies if needed,
Certain data suits being carried around by QueryStrings, with some suiting an ajax or json setup to get the data on demand, finally some just suiting a vanilla query and load into the page.

With all these at your disposal, it's a case of picking the right tool for the job. A 200 character string isn't suitable to be passed in a QueryString. If it's only use once on one page, then putting it in a session cookie could be suitable. If it's going to be updated frequently, then probably an ajax / json call would be better.

An ID however would lend itself better to being passed in a QueryString, along with form values (say the index of dropdownlists), etc, etc.

As a final note, it's worth checking how long these queries to the database are taking, as you could be putting in a lot of effort for milliseconds of returns.

RemarkLima
  • 11,639
  • 7
  • 37
  • 56
0

HTML5 local storage seems to be a good solution, but if HTML5 is not an option for you i did something similar as you are trying to do in the past by simply serializing options and save it into cookies.

joTa
  • 23
  • 3