Re: [jQuery] Best way for storing user preferences?

2006-10-11 Thread Webunity | Gilles van den Hoven
Raffael Luthiger wrote:
 3) Every time the page is loaded the js-script asks the server for a XML 
 (or JSON) file with the preferences in there.
   
Option 3, but save the data you got from the server in a cookie, which 
you destroy after 1 day or something like that. Each time the user 
changes the div, a new cookie is set and data is send back to the 
server. This saves you half in traffic and is the best solution if you 
ask me.

Gilles

p.s. there is a jQuery cookie plugin :p

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Best way for storing user preferences?

2006-10-11 Thread Mark Gibson
Raffael Luthiger wrote:
 2) The js-script gets generated each time the page is called. And the 
 corresponding vars are set in there.
 
 3) Every time the page is loaded the js-script asks the server for a XML 
 (or JSON) file with the preferences in there.
 
 5) More (and better) ideas?

I'd use a combination of these.

This same problem plagued me for a while too, I didn't like the idea of
generating JS on the fly, and an ajax request seemed overkill,
then it suddenly struck me today:

 From the backend, serialize your data as JSON, and place it in the
value attribute of a hidden input element. eg:

in HTML:

input type=hidden id=state value={hide:['section1','section2']}/

then in JS:

eval('var state = ' + $('#state').val());


I'm currently writing a plugin to pull JSON data from a document
like this (roughly based on XForms model/instance concepts), although
as I say I've only just started this today :)

- Mark Gibson

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Best way for storing user preferences?

2006-10-11 Thread Luke Lutman
I'd go for something like option 4, but instead of the custom attribute/DTD 
stuff, just give it 
a classname. i.e.:

div class=closed/div

Luke

Raffael Luthiger wrote:
 Hi,
 
 I've seen searching lately for a good way of storing preferences which a 
 jQuery script needs later on. The specific information the script needs 
 is the starting state of a div element (either open or closed). The 
 preferences are stored in a DB and sent from there somehow to the 
 browser. The sent and storing part is now the part I am searching for.
 
 After searching around for a while I found several ideas/solutions. But 
 none seems to be perfect for me. So I wanted to ask you what is the best 
 way to do it:
 
 1) Store the information in an invincible div at the end of the page. 
 And then parse this div. E.g:
 div id=prefs
 var1: value1;
 var2: value2;
 /div
 
 2) The js-script gets generated each time the page is called. And the 
 corresponding vars are set in there.
 
 3) Every time the page is loaded the js-script asks the server for a XML 
 (or JSON) file with the preferences in there.
 
 4) Write a XHTML DTD module in order to extend the div element with a 
 state-attribute. E.g:
 div state=closed
 
 5) More (and better) ideas?
 
 To say is that those pages are often reloaded.
 
  From my point of view 3) generates to much traffic on the net. 1) is 
 just a hack and therefor not really a good solution. I have my jQuery 
 scripts already in an external file. This way they can be cached by the 
 browser and don't have to be sent every time. So I don't really like 2) 
 either. Right now I would go with 4) unless someone has a better idea.
 
 Does anybody have a better solution?
 
 Raffael
 
 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


-- 
zinc Roe Design
www.zincroe.com
(647) 477-6016

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Best way for storing user preferences?

2006-10-11 Thread Raffael Luthiger
Thanks Gilles, Mark and Luke!

I was thinking about the cookie as well. But the problem I see here that 
a cookie can have in the maximum the size of 4k. It's not that I would 
reach the limit now, but I don't want to run into strange problems as 
soon as the application get larger over time. From this point of view 
Mark's solutions is more flexible. And I can generate those hidden input 
fields when I generate the page as well.

The idea with the classes can get a little bit messy since I already 
have IDs and classes on those divs.

At least I see that nobody would go for my favorite option. So I can 
probably drop it.

Raffael

Webunity | Gilles van den Hoven wrote:
 Option 3, but save the data you got from the server in a cookie, which 
 you destroy after 1 day or something like that. Each time the user 
 changes the div, a new cookie is set and data is send back to the 
 server. This saves you half in traffic and is the best solution if you 
 ask me.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Best way for storing user preferences?

2006-10-11 Thread Stephen Woodbridge
Raffael Luthiger wrote:
 Thanks Gilles, Mark and Luke!
 
 I was thinking about the cookie as well. But the problem I see here that 
 a cookie can have in the maximum the size of 4k. It's not that I would 
 reach the limit now, but I don't want to run into strange problems as 
 soon as the application get larger over time. From this point of view 
 Mark's solutions is more flexible. And I can generate those hidden input 
 fields when I generate the page as well.

Use the cookie to set a unique id, the get the uid and do an ajax call 
to the server to get the larger state info from a database, based on the 
uid.

-Steve

 The idea with the classes can get a little bit messy since I already 
 have IDs and classes on those divs.
 
 At least I see that nobody would go for my favorite option. So I can 
 probably drop it.
 
 Raffael
 
 Webunity | Gilles van den Hoven wrote:
 Option 3, but save the data you got from the server in a cookie, which 
 you destroy after 1 day or something like that. Each time the user 
 changes the div, a new cookie is set and data is send back to the 
 server. This saves you half in traffic and is the best solution if you 
 ask me.
 
 
 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/