3 ms·
It's been years since I've pointed out that something doesn't work when cookies are blocked, since it's at least half of the demos I click on. But out of curio
by gavinpc 10y ago
It's been years since I've pointed out that something doesn't work when cookies are blocked, since it's at least half of the demos I click on.
But out of curiosity, I just checked for an error message on this (blank) page:
SecurityError: The operation is insecure.
e.exports.getItem()
So... it's a local storage call, which uses the domain's cookie permissions. That makes more sense (than cookies).
Still, how can a first visit to a site require a getItem call before displaying anything at all?
Others commenters are saying this is not even a demo, but just a landing page. Wow. You might be overengineering.
- 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.