{"id":1605,"date":"2015-12-28T16:13:35","date_gmt":"2015-12-28T21:13:35","guid":{"rendered":"http:\/\/andrewpallant.ca\/wordpress\/?p=1605"},"modified":"2020-01-10T11:23:34","modified_gmt":"2020-01-10T16:23:34","slug":"cookie-monster-would-be-disappointed","status":"publish","type":"post","link":"http:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/","title":{"rendered":"Cookie Monster Would Be Disappointed"},"content":{"rendered":"<p>Using localStorage or sessionStorage would disappoint Cookie Monster.<\/p>\n<p>My go to for a website to store data temporary was to use cookies.  I would use cookies for storing user preferences, scores, shopping carts and more.  Cookies can be a problem though as many people stop excepting cookies and they are difficult to manage.   <!--more--><\/p>\n<p>Now I use either <strong>localStorage<\/strong> or <strong>sessionStorage<\/strong>.  The difference of syntax is subtle, but the usage is very different.  Both of these is a good replacement for cookies which would disappoint Cookie Monster.<\/p>\n<p>If I am creating a scoreboard for a game; I often use <strong>localStorage<\/strong>.  I like more scoreboards to persist for a long period of time event after the browser is closed.  If I am creating a shopping cart; I often will use <strong>sessionStorage<\/strong> so that the shopping cart persists during the usage of the site, but is discarded when the user closes the browser.  With <strong>localStoarge<\/strong> it is assumed the user wants to maintain the data for a long time.  With <strong>sessionStorage<\/strong> it is assumed the data is not wanted when the user is done their browser.<\/p>\n<p>To demonstrate the similarity in syntax and difference in usage, I have created the code below.  One must try in order to see the difference.<\/p>\n<p><strong>localStorage<\/strong> &#8211; keep long term<\/p>\n<pre  style=\"font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;\"><code style=\"color:#000000;word-wrap:normal;\"> \/\/ Initialize Scoreboard of Correct and Incorrect Values  \r\n if (typeof localStorage['correct'] == 'undefined') { localStorage['correct'] = 0; }  \r\n if (typeof localStorage['notcorrect'] == 'undefined') { localStorage['notcorrect'] = 0; }  \r\n\r\n \/\/ Increment Value  \r\n var iCorrect = parseInt(localStorage['correct']);  \r\n iCorrect++;  \r\n\r\n \/\/ Update Display and storage  \r\n $(\"#iscorrect\").html(iCorrect);  \r\n localStorage['correct'] = iCorrect;  \r\n<\/code><\/pre>\n<p><strong>sessionStorage<\/strong> &#8211; keep temporary<\/p>\n<pre  style=\"font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;\"><code style=\"color:#000000;word-wrap:normal;\"> \/\/ Initialize Scoreboard of Correct and Incorrect Values  \r\n if (typeof sessionStorage['correct'] == 'undefined') { sessionStorage['correct'] = 0; }  \r\n if (typeof sessionStorage['notcorrect'] == 'undefined') { sessionStorage['notcorrect'] = 0; }  \r\n\r\n \/\/ Increment Value  \r\n var iCorrect = parseInt(sessionStorage['correct']);  \r\n iCorrect++;  \r\n\r\n \/\/ Update Display and storage  \r\n $(\"#iscorrect\").html(iCorrect);  \r\n sessionStorage['correct'] = iCorrect;  \r\n<\/code><\/pre>\n<p>The following browsers will support <strong>sessionStorage<\/strong> and <strong>localStorage<\/strong><br \/>\nFireFox 3.5+<br \/>\nChrome  4.0+<br \/>\nIE      8.0+<br \/>\nSafari  4.0+<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using localStorage or sessionStorage would disappoint Cookie Monster. My go to for a website to store data temporary was to use cookies. I would use cookies for storing user preferences, scores, shopping carts and more. Cookies can be a problem though as many people stop excepting cookies and they are difficult to manage.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149,96],"tags":[261,260,256,262,263],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Cookie Monster Would Be Disappointed - LDNDeveloper<\/title>\r\n<meta name=\"description\" content=\"Using localStorage or sessionStorage would disappoint Cookie Monster.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Cookie Monster Would Be Disappointed\" \/>\r\n<meta property=\"og:description\" content=\"Using localStorage or sessionStorage would disappoint Cookie Monster\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\" \/>\r\n<meta property=\"og:site_name\" content=\"LDNDeveloper\" \/>\r\n<meta property=\"article:published_time\" content=\"2015-12-28T21:13:35+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2020-01-10T16:23:34+00:00\" \/>\r\n<meta name=\"author\" content=\"ldnDeveloper\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:title\" content=\"Cookie Monster Would Be Disappointed\" \/>\r\n<meta name=\"twitter:description\" content=\"Using localStorage or sessionStorage would disappoint Cookie Monster\" \/>\r\n<meta name=\"twitter:creator\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:site\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ldnDeveloper\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\"},\"author\":{\"name\":\"ldnDeveloper\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"headline\":\"Cookie Monster Would Be Disappointed\",\"datePublished\":\"2015-12-28T21:13:35+00:00\",\"dateModified\":\"2020-01-10T16:23:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\"},\"wordCount\":234,\"publisher\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"keywords\":[\"Cookies\",\"HTML5\",\"jQuery\",\"localStorage\",\"sessionStorage\"],\"articleSection\":[\"jQuery\",\"Web\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\",\"name\":\"Cookie Monster Would Be Disappointed - LDNDeveloper\",\"isPartOf\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#website\"},\"datePublished\":\"2015-12-28T21:13:35+00:00\",\"dateModified\":\"2020-01-10T16:23:34+00:00\",\"description\":\"Using localStorage or sessionStorage would disappoint Cookie Monster.\",\"breadcrumb\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/andrewpallant.ca\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cookie Monster Would Be Disappointed\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#website\",\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/\",\"name\":\"LDNDeveloper\",\"description\":\"Learning, Growing and Sharing.\",\"publisher\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\",\"name\":\"ldnDeveloper\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"contentUrl\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"width\":512,\"height\":512,\"caption\":\"ldnDeveloper\"},\"logo\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\"},\"description\":\"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf\",\"sameAs\":[\"http:\/\/www.andrewpallant.ca\",\"https:\/\/x.com\/LdnDeveloper\"],\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Cookie Monster Would Be Disappointed - LDNDeveloper","description":"Using localStorage or sessionStorage would disappoint Cookie Monster.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/","og_locale":"en_US","og_type":"article","og_title":"Cookie Monster Would Be Disappointed","og_description":"Using localStorage or sessionStorage would disappoint Cookie Monster","og_url":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/","og_site_name":"LDNDeveloper","article_published_time":"2015-12-28T21:13:35+00:00","article_modified_time":"2020-01-10T16:23:34+00:00","author":"ldnDeveloper","twitter_card":"summary_large_image","twitter_title":"Cookie Monster Would Be Disappointed","twitter_description":"Using localStorage or sessionStorage would disappoint Cookie Monster","twitter_creator":"@LdnDeveloper","twitter_site":"@LdnDeveloper","twitter_misc":{"Written by":"ldnDeveloper","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#article","isPartOf":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/"},"author":{"name":"ldnDeveloper","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"headline":"Cookie Monster Would Be Disappointed","datePublished":"2015-12-28T21:13:35+00:00","dateModified":"2020-01-10T16:23:34+00:00","mainEntityOfPage":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/"},"wordCount":234,"publisher":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"keywords":["Cookies","HTML5","jQuery","localStorage","sessionStorage"],"articleSection":["jQuery","Web"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/","url":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/","name":"Cookie Monster Would Be Disappointed - LDNDeveloper","isPartOf":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#website"},"datePublished":"2015-12-28T21:13:35+00:00","dateModified":"2020-01-10T16:23:34+00:00","description":"Using localStorage or sessionStorage would disappoint Cookie Monster.","breadcrumb":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/andrewpallant.ca\/wordpress\/cookie-monster-would-be-disappointed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/andrewpallant.ca\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Cookie Monster Would Be Disappointed"}]},{"@type":"WebSite","@id":"http:\/\/andrewpallant.ca\/wordpress\/#website","url":"http:\/\/andrewpallant.ca\/wordpress\/","name":"LDNDeveloper","description":"Learning, Growing and Sharing.","publisher":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84","name":"ldnDeveloper","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","contentUrl":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","width":512,"height":512,"caption":"ldnDeveloper"},"logo":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/"},"description":"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf","sameAs":["http:\/\/www.andrewpallant.ca","https:\/\/x.com\/LdnDeveloper"],"url":"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/"}]}},"_links":{"self":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1605"}],"collection":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=1605"}],"version-history":[{"count":4,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1605\/revisions"}],"predecessor-version":[{"id":1609,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1605\/revisions\/1609"}],"wp:attachment":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=1605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=1605"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=1605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}