code4sac / wicit

A simple node/express app for finding locations that accept WIC in California, using data from the new California Department of Public Health open data portal.
http://findwic.com/
MIT License
19 stars 20 forks source link

Cache geolocation result to localstorage. #35

Closed donmccurdy closed 9 years ago

donmccurdy commented 9 years ago

Fixes #18. Caches geolocation result to localStorage for ~24 hours.

NOTE: This isn't quite ready to be merged (there's a bug in Safari I need to look into), but I thought I'd get feedback about the approach, like using localStorage as opposed to cookies or another session storage method.

This wouldn't need to be localStorage (interested to hear your thoughts) but here's my reasoning:

  1. Generic session storage can be kept in cookies, server memory, or another datastore, but usually involves either (a) including it in the page body or (b) making an AJAX request for that data. Since (a) would break any future possibility of using a CDN like CloudFlare to add caching or HTTPS, and (b) would dramatically slow down the pageload, it might be better to keep this client-side.
  2. Cookies have rather particular encoding needs (no semicolons, commas, or whitespace) so we'd probably want to use one of the jQuery cookie plugins if we went that route. Plugins are meh.
  3. LocalStorage is supported on all browsers that support the geolocation API (as far as I know), and doesn't require any plugins.
donmccurdy commented 9 years ago

The issue I ran into with Safari should be fixed now. :)

jesserosato commented 9 years ago

@donmccurdy Is this ready to go then? Local storage is :+1: as far as I'm concerned.

donmccurdy commented 9 years ago

Should be good, yeah. Checked against Chrome/FF/Safari/IE9.