Monday, 20 July 2009

Websiting

This morning I did some more website stuff, watched In The Night Garden with L, vacuumed my room, then did more website stuff.

I needed to store a user preference value in javascript that would persist between page views. I found a cookie plugin for jQuery, which made setting cookies nice and easy. Then I thought that it might be a good idea to just have a 'prefs' cookie, and store the user preferences in it as a JSON object.

After some googling I found another jQuery plugin, JSONCookie. It seems to require a separate JSON decoding/encoding library, which is a bit strange, since jQuery must already have it's own JSON parser built in to parse JSON objects received with its $.getJSON() function.

Anyway, after getting that working, I realised that actually storing the user preferences all in one cookie might not be such a good idea, since it means that you have to parse the cookie contents each time you want to retrieve a value stored in the JSON cookie, rather than just referring to a single cookie that returns its value and doesn't need parsing. Also, if you are using one cookie, that cookie will need to be sent with all requests, whereas with seperate cookies you can ensure they are only with requests on a certain path.

If you have complicated/lots of user preferences to store though, then I think a JSON cookie would be a good idea.

After lunch I went on Animal Crossing, then I checked my spleenmail. I carried on working on my photo website for the rest of the day.

Food
Breakfast: Honey loops; cup o' tea.
Lunch: Mature cheddar cheese with iceberg lettuce sandwich; white grapes; slice of Ludlow Food Centre Shropshire Fruit Cake; Fox's Classic; cup o' tea.
2 o' clock snack: ½ Fudge Factory Chocolate Chip Cookie; cup o' tea.
Dinner: Bacon quiche; potatoes; peas. Pudding was spotted dick with custard. Coffee; Sainsbury's Turkish delight chocolate.

No comments: