4 ms·
> Still, how can a first visit to a site require a getItem call before displaying anything at all? Something like "the index.html page is empty, and gets popul
by zyxley 10y ago
> Still, how can a first visit to a site require a getItem call before displaying anything at all?
Something like "the index.html page is empty, and gets populated from other templates by (insert Javascript framework here)".
There's this weird fetish now for doing literally everything in Javascript instead of rendering pages server-side ever.
- gavinpc 10y agoSo make this your storage module: // For a given domain, localStorage uses the same permissions as cookies. When // cookies are blocked, attempts to access localStorage will throw a Security // exception. We do that test once here so that we can safely test for this // object everywhere else. define(function() { try { var K = '__test', V = 1, s = window.localStorage; if (s) { s.setItem(K, V); if (V == s.getItem(K)) { s.removeItem(K); return s; } } } catch(e) {} return null; }); I mean, I like javascript too. But whether or not your site is rendered entirely by javascript, you should be feature testing for localStorage. And if your site is rendered entirely by javascript, (1) it's impossible that rendering to a first-time visitor can depend on something previously stored there. (2) your site will be hosed by any uncaught error during load For this to happen on an essentially static page is just laughable. /rant. Okay, I'm good until 2020.