NOTE: We ended up using store.js with json because ie7 apparently doesn’t come equiped with JSON. Tom and I broke our heads trying to figure out why store.enabled wasn’t true for ie7. It came down to the fact that ie7 didn’t have JSON.
Thought this was a cool little way to store whether a td square had been clicked on…
1234567891011121314151617181920
addRedTiles: ->
selected = store.get("board_#{@board_id}")
for tile_number in selected
$("[data-title-num=#{tile_number}]").addClass('clicked_space')
duringBoardClick: ->
if store.enabled
$('td').click =>
$(event.target).toggleClass('clicked_space')
clicked_tiles = []
all_clicked = $('td.clicked_space')
for tile in all_clicked
clicked_tiles.push $(tile).attr('data-title-num')
store.set("board_#{@board_id}", clicked_tiles)
else
console?.log? 'store is not enabled'
This needed to be updated b/c of event.targer
1234567891011121314151617
duringBoardClick:->ifstore.enabledboard_id=@board_id\\noticethatIdeclaredtheabovevariable$('td').click->\\andchangedthistoasingle->$(@).toggleClass('clicked_space')clicked_tiles=[]all_clicked=$('td.clicked_space')fortileinall_clickedclicked_tiles.push$(tile).attr('data-title-num')store.set("board_#{board_id}",clicked_tiles)\\boardthenbecomesalocalelseconsole?.log?'store is not enabled'
local storage versus cookies
client versus server -> Cookies and local storage really serve difference purposes. Cookies are primarily for reading server-side, local storage can only be read client-side. So the question is, in your app, who needs this data — the client or the server? If it’s your client (your JavaScript), then by all means switch. You’re wasting bandwidth by sending all the data in each HTTP header. If it’s your server, local storage isn’t so useful because you’d have to forward the data along somehow (with Ajax or hidden form fields or something). This might be okay if the server only needs a small subset of the total data for each request.
Size -> Apart from being an old way of saving data, Cookies give you a limit of 4096 bytes (4095, actually) - its per cookie. Local Storage is as big as 5MB per domain.