{"id":10552,"date":"2021-03-12T15:57:41","date_gmt":"2021-03-12T15:57:41","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=10552"},"modified":"2024-04-08T14:57:52","modified_gmt":"2024-04-08T14:57:52","slug":"javascript-storage-and-web-worker","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=10552","title":{"rendered":"Client-side storage (Web browser)"},"content":{"rendered":"<p><strong>Overview<\/strong><\/p>\n<ol>\n<li>User data<\/li>\n<ol>\n<li>Cookies<\/li>\n<li>Web Storage<\/li>\n<li>IndexedDB<\/li>\n<\/ol>\n<li>Cache<\/li>\n<ol>\n<li>HTTP Cache<\/li>\n<li>GPU Cache<\/li>\n<li>Code Cache<\/li>\n<\/ol>\n<\/ol>\n<hr>\n<p><strong>1.1 Cookies<\/strong><br \/>\nThe data gets received from the server and then transferred with every request.<\/p>\n<ol>\n<li>Initially (Without cookies)<br \/>\nRequest<\/p>\n<pre>\r\nGET \/ HTTP\/1.1\r\nHost: www.example.org\r\n...\r\n<\/pre>\n<p>Response<\/p>\n<pre>\r\nHTTP\/1.1 200 OK\r\n...\r\nSet-Cookie: sessionId=0123456789; Path=\/; Domain=example.com\r\n...\r\n<\/pre>\n<\/li>\n<li>Afterward (With cookies)<br \/>\nRequest<\/p>\n<pre>\r\nGET \/ HTTP\/1.1\r\nHost: www.example.org\r\n...\r\nCookies: sessionId=0123456789\r\n...\r\n<\/pre>\n<p>Response<\/p>\n<pre>\r\nHTTP\/1.1 200 OK\r\n...\r\n<\/pre>\n<\/li>\n<\/ol>\n<hr>\n<p><strong>1.2 Web Storage (aka. DOM Storage)<\/strong><br \/>\nThe data gets created locally and isn&#8217;t transferred to the server with every request.<\/p>\n<table style=\"text-align: center\">\n<col style=\"width:20%\">\n<col style=\"width:40%\">\n<col style=\"width:40%\">\n<tr>\n<th>Type<\/th>\n<th>Local Storage<\/th>\n<th>Session Storage<\/th>\n<\/tr>\n<tr>\n<th>Data<\/th>\n<td colspan=\"2\">Key-Value<\/td>\n<\/tr>\n<tr>\n<th>Scope<\/th>\n<td>One origin <br \/> (across all windows and their tabs for one web browser instance)<\/td>\n<td>One tab<\/td>\n<\/tr>\n<tr>\n<th>Cleanup<\/th>\n<td>Explicitly (e.g. by the code)<\/td>\n<td>Implicitly (with closing the tab)<\/td>\n<\/tr>\n<\/table>\n<p>The access happens synchronous and can only be done by the main thread.<br \/>\n(Your UI will possibly freeze.)<\/p>\n<hr>\n<p><strong>1.3 IndexedDB<\/strong><br \/>\nSeems like the Local Storage, but is designed to store way more and even complex data.<\/p>\n<p>The access happens asynchronous and can be done by the main thread and running web workers.<br \/>\n(Your UI won&#8217;t freeze if done by a web worker, else it&#8217;s still possible.)<\/p>\n<hr>\n<p><strong>2.1 HTTP Cache<\/strong><br \/>\nThe cached data are HTTP object pairs (request\/response) for a better loading performance.<\/p>\n<p>The specific behavior gets defined via the &#8216;Cache-Control&#8217; label in the HTTP-Header:<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.max-sperling.bplaced.net\/wp-content\/uploads\/2021\/03\/Cache-Control.png\" class=\"aligncenter\" \/><\/p>\n<p class=\"aligncenter\">Source: <a href=\"https:\/\/web.dev\/http-cache\/\">https:\/\/web.dev\/http-cache\/<\/a><\/p>\n<hr>\n<p><strong>2.2 GPU Cache<\/strong><br \/>\nThe cached data are shaders (set of instructions, executed at once for multiple pixels) for a better rendering performance.<\/p>\n<hr>\n<p><strong>2.3 Code Cache<\/strong><br \/>\nThe cached data are precompiled code (e.g. javascript in bytecode) for better execution performance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview User data Cookies Web Storage IndexedDB Cache HTTP Cache GPU Cache Code Cache 1.1 Cookies The data gets received<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[55],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/10552"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10552"}],"version-history":[{"count":3,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/10552\/revisions"}],"predecessor-version":[{"id":17325,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/10552\/revisions\/17325"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10552"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}