{"componentChunkName":"component---src-templates-blog-js","path":"/blog/how-a-web-developer-uses-storage-in-the-browser-part-2","result":{"data":{"markdownRemark":{"frontmatter":{"title":"How a web developer uses storage in the browser part 2","path":"/blog/how-a-web-developer-uses-storage-in-the-browser-part-2","image":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='267'%20viewBox='0%200%20400%20267'%20preserveAspectRatio='none'%3e%3cpath%20d='M0%2033l1%2033a707%20707%200%200033-9c-3-1-2-2%204-2l5-1%208-1c9-1%209-1%207-2s3-3%2011-4l8-1v-5l1-2h6l3%201c2%200%202%200%202-7v-9l-1-1%2011-2a1448%201448%200%200015%200l-18%203%202%201c2%201%202%203-1%203l-1%203c1%204%205%206%207%203h1c0%202%203%201%203-1h1l2%201%202-1v-1l1%201h3l1%201v-6c2-2%204%200%204%203l1%202v-3l2-4%201-3h-2l1-2%201-2c-1-1%200-2%209-3h11v1l-17%202c-3%200-2%207%200%207h3c1-1%201-1%202%201%201%204%202%204%205%202%203-1%204-3%201-3-1-1%200-1%202-1l3-1h3c2%200%204-2%204-6v-3l2-1h4V1h-8l-18%201-12%201h-8l3-1h6l6-1-64-1H0v33M158%207c0%207%200%207%208%205%203%200%203%200%203-6V0h-11v7m13-5v4c0%2015%200%2014%203%2014%202-1%203%200%203%201h1l1-2v2c0%203%202-1%202-6%200-4%201-5%205-5v1c-1%201-2%206-1%207l1%201c-1%201%200%204%202%203l1%201h1c2-3%204-2%204%202l1%202%201-3c-1-3%200-4%201-4s1-1-1-3c-1-1-1-1%201-1l2%201%209%202h9l1-2%201-16c1-1-1-1-10-1-8%200-11%201-11%202v5l-1%203-1-5%201-4-13-1c-12%200-13%200-13%202m52%203l1%2010%201%205v-5c0-6%201-4%202%204%200%202%204%203%2015%204l7%201v-4l1-11%201-6-6-1-5-1-9-1h-9l1%205m34-4v22l3-13%201-6-1%2019c-1%203%200%204%207%204%205%201%208%200%204-1-1-1-1-1%201-2l1-1h-1l-1-1%205-1%201-1-2-2c-4%200-4%200-3-1h3c2%200%203%200%202-1l2-2h1v2l1-1%202-2c3%200%205%202%203%203v3h2l2-1c2%200%2010-5%2010-6h1l3-1c1-2%200-2-6-2l-2-1h-2c-3%200-15-2-14-3%200-1%207-1%2022%201a389%20389%200%20009%202c-1%201%201%201%205%202l9-1%208-5%206-3c0-2-82-1-82%200m93%200l-7%205-6%203-9%205c-8%204-9%204-14%203-6-1-10%200-10%201h-1c-2%200-2%200%200%201%201%201%201%201-1%201h-1l-2%202-3%201-6%204c-8%203-8%204-2%205l15%203c11%202%2012%202%2012-3%200-3%200-4%202-4v8l-1%203v7c2%203%208%203%208%201%201-2%201-2%202-1%200%202%202%203%204%203%201%200%201-1-1-1-3-2-3-3%201-2%204%202%209%202%2010%201h1c0%201%201%202%204%202l4%202c0%202%207%206%209%206h3l3-1%201-1v-1l1%201h1l2-1c3%202%209%202%209%200l1%201%202%203a8867%208867%200%200010%202c0%202%202%204%206%204l3%201V7l-9-1-8-2h2l3-1%202-1c2%200%202%200%201-1h-41M161%2014c-7%201-8%202-8%203v3c-1%201%200%201%207%201%208%200%2010-1%2010-4%200-4%200-4-9-3m106%2023l-3%202%2017%202%2023%204c9%202%2010%201%2010-3s0-4-2-3l-4%202c-2%202-10%201-30-3l-5-2c0-1-2-1-6%201m-48%208c3%202%207%204%2013%204l2%201h6c2%202%208%204%2013%203h2v2l1-1h5l2%201-1%201h3l5-1c2%200%202%200%200-1a688%20688%200%2001-51-11h-2l2%202m-28%201a243%20243%200%2000-28%206l-9%201-5%202v8c0%2012%201%2014%203%2013l3-1h2c1%202%202%201%202-3%200-3%200-4-2-4v-1h2c0%201%203%201%2011-2%206-1%2011-1%2011%201l-3%201c-6%200-7%201-6%204%200%202%200%203-1%202h-5l2-2%202-1-2-1-4%201-1%206c0%205%201%205%203%205l2-1%203-1%203-1%204-2%201-3c1-3%200-3-4-2h-2c0-2%207-4%208-2l5-1c4-2%207-2%207%200%201%201%206%201%206-1l3-1%2010%203c4%200%205%202%203%204h-3l-1-1-4-2c-4-1-4-1-6%201h-5c-2%200-3%200-3%202l2%201c1-1%204%200%206%201l16%204%204%202h9c6-1%208-2%204-4-1%200-2-1-1-2l2%201%201%201%202%201c2%202%203%203%204%202%201%200%201-1-1-1-3-1-3-3%201-2%201%200%202%200%202-2a100%20100%200%20012-17c2-2%200-3-13-6-35-8-34-8-34%204%200%208-1%2010-3%208l-1-17-1-2-3%201m-50%2010c-6%201-8%207-6%2016v3l6-1%205-2h-1c-2%200-2-1-2-3s0-3%201-1c1%205%202%202%202-5l-1-8-4%201m107%2011v13l2%202%205%201c3%202%203%202%203-1%202-6%203-22%202-23l-11-3-1%2011m16-6c3%201%202%203%200%203l-2%202%201%201v1c-1%201-2%209-1%2011v1c-2%200-1%203%201%204%203%200%204%200%202%201-3%202-1%204%206%207%208%202%209%202%209%200s-1-3-3-3l-3-2%2014%204%206%202%205%201%205%202%204%201%204%202c3%201%204%200%203-3l2-2c2-1%2025%205%2028%207l-3%2014c-1%203%202%204%204%202%202-1%209%200%2012%203%205%204%205%204%206-1l2-4v1l2%203c3%200%203%200%201%202h-2l-2%201-1%204%202-1%201-1v1c0%201%201%202%205%203l6%202c2%201%203%201%205-1l2-3%208-7-6-2a869%20869%200%2001-20-6c1-2%207-3%208-2l10%204c9%203%2011%203%2013%202h2v4c1%201%201-8%201-20a182%20182%200%2000-1-18v4l-14-4-36-8c-33-8-34-8-33-5l3%201h1c-1%202-1%202%201%202l3%201%202%201%205%201h3l2%201v1c-1%201%200%201%202%201l3%201-1%201a104%20104%200%2001-18-4%20468%20468%200%2001-59-15v1M72%2064A3793%203793%200%20015%2077l-4%201v22l1%2022%204%203c3%203%203%203%206%201%204-2%206-4%206-5%200-2%201-2%204-2h4l2-1%208-3c3-2%206-3%207-2%202%200%202%200%201%201l-1%202%202-1%202-1-1%202c-1%202-1%205%201%205l1-2%202-2v2l3%202c4%202%206%201%203-2l-2-3%202-1c2%200%202%200%201-1l-2-3c0-1%202-2%202%200l4%202h4l-4-2-4-3c-2%200-3-3-2-4l9-1v1l4%201h3l-3-2-1-2h4l2%201c1%200%201-1-1-3l-3-2h7l-3-2-1-1c0-2%203-2%204-1l4%201c1%200%201-1-2-2l-3-2c0-2-3-1-3%200l-2%201c0-1%2010-13%2013-14%203-2%202%200-3%204-3%203-4%205-3%206l1%201c-1%201%208%204%209%203l-3-2c-5-2-5-3-1-3%203-1%203-1%201-1l-2-2c1-1%207%200%209%201l3%201c0-1-1-2-3-2-4-2-4-4%200-4h3l-3-1c-3-2-1-3%204-2h3l-3-1c-3-3-3-4%201-4h2c-2%200-3-2-1-2l9-2c9-3%205-4-5-1-4%201-7%202-8%204-3%203-8%207-8%205h-2c-2%200-2%200-1-3s1-3-3-1l-4%201h-1c-3%201-24%205-25%204-1%200%206-3%208-2v-1c-1-1-1-1%202-1a158%20158%200%200018-4l6-3c4-5%204-5-11-1m54%205c-4%205-6%206-10%207-6%201-12%205-12%208l-2%202c-3%200-9%209-8%2010s1%201-1%201l-7%205c-2%203-4%205-2%205a144%20144%200%200114-5l17-5%205-1v-6c-1-7%200-9%202-9l1-1c-1-1%200-2%204-3%205-1%206-2%205-8%200-6%200-6-6%200m5%2010c-4%201-6%202-5%203v3l2%202v1c-3%202-2%205%201%204l2-1%202-1c1%201%202%200%203-1l2-3c1-1%202-2%202-5%200-5%200-5-9-2m213-1l1%201v1c-1%201-1%201%202%201h1c-1%201-1%201%202%201%205%200%206%202%205%205l-5%2021%201%204%203-11a188%20188%200%20013-13c0-2%202-5%204-4%202%200%202%200%201-1l-10-2-1-1-3-2h-4M191%2098l-4%202c-3%200-7%201-11%204l-5%201c-2%200-3%201-3%205l1%205v1l-1%204c1%203%201%203%202%202h2l3-1c1-1%202-2%203-1s1%201-1%201l-2%202h2l5-2%208-1c-2%200-1%203%201%203%201%200%202%201%202%203l1%202v-6l1-6V99c0-2%200-2-4-1m128%201l-2%202c-2%200-2%200%200%201l2%201h-2c-2%200-2%200-1%201v2c-2%201%200%204%205%205a198%20198%200%20018%201v-1l1%201c0%202%207%204%208%203l-1-1-1-1-3-2c-3-1-4-2-3-3%200-2%204-4%206-3%201%201%202-1%202-3l-4-1-8-3c-5-1-6-1-7%201m-119%201l-2%208v6l5%202%206%202%204%202%201%201%203%202c3%203%208%204%208%203l1-17c1-2%200-3-5-5l-12-4c-7-2-7-2-9%200m-108%206l-8%203c-6%201-16%209-15%2011%201%200%207-2%209-4l4-1%203-3%203-1%203-2%204-2%201-1h-4m66%203l-5%202%201%206c1%2015%201%2015%204%2015h2l3-1c3-1%203-1%202-6v-11c0-8%200-8-7-5m70%206v10c-2%202%203%203%207%202%204-2%205-3%205-7l1-5c1-3%201-3-3-5l-7-3h-3v8m-80-2l1%202c1%201%201%201-1%202h-3v-3l-1%201-2%201-10%203a187%20187%200%2001-22%208%20428%20428%200%2001-39%2014c-7%202-8%202-5%204l8%208%203%205%201%201%201%204c2%201%202%201%205-1%201-2%204-3%207-4%205-2%2010-5%206-5-2%201-3%200%200-2%202-2%202-2%205%200h4l-1-1c-2-1-2-1%201-2l4-3%204-1c3%200%204-1%204-2h4l2-2%206-2c2-2%205-3%207-2%202%200%203-1%203-2%201-1%202-2%205-2%204-1%208-3%207-5l-5%202-4%202-2-3c-1-2-1-2%201-3l2-2v-2l1%201%201%202-1%202c-3%202-1%203%203%201%203-2%204-2%203-6v-6c0-3-1-4-3-2m50%207l-1%201c-2%200-3%204-1%205l1-1%201-1v2c0%202%200%202%202%201%201-1%201-1%201%201-1%201%200%202%202%203l5%202c3%201%203%201%203-4v-6l-6-2c-6-2-8-3-7-1m-50%2017l1%204%201%203-2-1c0-2-1-2-2-1l-2%201h-3c-2%200-3%203-1%203l1%204c-1%205%203%207%2010%204%203-1%206-2%207-1l1-1v-6l-1%201h-2c-2-3-2-4-1-4l1-2c0-2-2-3-2-1l-2%201-2-2v-3l-2%201m147%203l-13%203c-9%202-10%202-4%204%2011%204%2013%205%2011%207-2%200-2%202-2%203v2c-1%200-2-1-1-2%200-2-1-3-8-6-10-4-13-5-12-2%201%201%200%201-1%201-3%200-4-2-1-3%202%200%201-2-3-4s-9-1-14%201l-6%202v1c4%201%201%202-4%201-3-1-13%200-13%202a142%20142%200%200024%2010l4%202%206%202h2l2-1-1%202c-1%201-1%201%201%201h5l2%201c-1%201%201%202%205%202l4-1-3-1c-3-1-5-3-3-3v-1h-3c-1%201-3%200-9-2-7-4-9-6-2-4h4l3%201%203%202%204%201%205%201%201-1%204%201%201%201h-3c-3%200-3%200%201%202%202%201%202%201%204-2l1-3v3l-2%205c-1%201%202%202%206%203%207%200%208%201%209%202%202%202%203%201%203-2l2-6c0-1%200-2-3-4-4-3-6-3-7%200%200%201-1%202-2%201l-1%201%201%201%201%202h-2l-1-5%201-4c0-2%205-3%208-1%204%203%206%203%206%200%202-6%203-13%202-14%200-3-6-4-12-2m-245%207l-7%202-1%201-2%201h-3c-1%201%208%2010%209%2010v-1c-1-2-1-3%201-3%200%200%202%201%202%203%201%202%202%202%206%201%206-2%206-2%204-8v-6c1-3-1-3-9%200m65%2013c-8%204-12%205-12%203s-2-1-8%202l-7%201-1%201-2%201c-2%200-2%200%200%204l5%206c2%203%201%204%2015-3l12-5%206-3v-4c-1-5-1-6-8-3m90%206l-4%202-10%209c-3%204-1%206%203%203%202-1%2012%201%2015%203l2%201h2c0%201%202%203%205%204l8%205%204%202v2l-1%207-2%208v4h1c1-5%202-6%203-2l2%203c2%200%202%200%201-1-2-3-2-7%202-9l2-4c1-1%201-1%201%201s2%203%207%205l2%201%201%201%204%202c4%203%2010%205%2011%204l1%201%202%201%205-1c2%200%204-2%205-3l3-2h1l-2-1v-1h2c1%202%204-1%204-4l2-1c2%200%201-1-3-3-6-3-6-3-6-1v2l-1-2-1-3-2%202%201%202%201%202%201%204c1%202%201%202-4%200l-1%201-1%203c-1%200-1-12%201-15l-22-13c-1%200-2%202-2%207%200%206-1%208-2%208v-14c1-1%200-3-8-6-8-5-8-5-9%201%200%202-1%201-1-2-1-2-1-3%201-3l-2-2c-3-2-4-2-4%200-1%202-1%202-1%200l-1-3-1%203-1%206-1-6c1-5%201-5-2-6l-3-1-6-3-2%202m-63%2020l-3%202c-2%200-17%207-18%209v2l1%204%201%204c1%201-1%205-2%205l-1-3-1-11-8%205c0%202%206%2010%208%209l1%202c-1%201%203%206%204%205l5%202c4%202%204%200%200-2-2-2-3-3-1-3%201-1%202-1%204%201%203%202%204%202%201-2-3-2-2-5%201-3%203%203%205%202%202%200-2-2-3-4%200-4l1-2%202-2c2%200%202%200%201-2-1-1-1-1%201-2%202%200%203-1%203-2l2-1%202-1-1-1-2-1c0-8-1-10-3-8m43%204c-4%203-6%204-6%206h-1l-2%202-7%205-8%205-9%2011-11%2012-1%201c0%201-1%202-2%201l2%203c4%204%207%205%205%203-1-2%203-6%2010-10%202%200%203-1%203-2l-3%201c-3%202-4%201-1-1l1-2v-2l2-2c0-1%201-2%202-1l4-1-1-1c-4%202-2-1%202-2l4-3%201-1c2%200%204-3%203-4l2-1h1c0-2%200-2%201-1l2-1-2-1-2-2c0-1%201-1%205%201l6%202%2010-5h5c4%202%208%201%208-3%200-2-10-10-13-9h-2c0-2-2-1-8%202m-8%2034a7381%207381%200%2001-22%2014l26%2020%203%202v-2c-1-3-4-6-15-14l-7-6%2032-21%203-2%207%205c13%208%2020%2011%2018%209-1-2-24-17-25-17l-20%2012M0%20251v16h11c9%200%2010%200%209-2a139%20139%200%2001-15-22c0%201-3-2-3-4l-1-2c-1-1-1%204-1%2014'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.5037593984962405,"src":"/static/d95f25cddb6a418707b3ced16003c967/14b42/gabriel-sollmann-704393-unsplash.jpg","srcSet":"/static/d95f25cddb6a418707b3ced16003c967/f836f/gabriel-sollmann-704393-unsplash.jpg 200w,\n/static/d95f25cddb6a418707b3ced16003c967/2244e/gabriel-sollmann-704393-unsplash.jpg 400w,\n/static/d95f25cddb6a418707b3ced16003c967/14b42/gabriel-sollmann-704393-unsplash.jpg 800w,\n/static/d95f25cddb6a418707b3ced16003c967/47498/gabriel-sollmann-704393-unsplash.jpg 1200w,\n/static/d95f25cddb6a418707b3ced16003c967/0e329/gabriel-sollmann-704393-unsplash.jpg 1600w,\n/static/d95f25cddb6a418707b3ced16003c967/5dbb2/gabriel-sollmann-704393-unsplash.jpg 5557w","srcWebp":"/static/d95f25cddb6a418707b3ced16003c967/58556/gabriel-sollmann-704393-unsplash.webp","srcSetWebp":"/static/d95f25cddb6a418707b3ced16003c967/61e93/gabriel-sollmann-704393-unsplash.webp 200w,\n/static/d95f25cddb6a418707b3ced16003c967/1f5c5/gabriel-sollmann-704393-unsplash.webp 400w,\n/static/d95f25cddb6a418707b3ced16003c967/58556/gabriel-sollmann-704393-unsplash.webp 800w,\n/static/d95f25cddb6a418707b3ced16003c967/99238/gabriel-sollmann-704393-unsplash.webp 1200w,\n/static/d95f25cddb6a418707b3ced16003c967/7c22d/gabriel-sollmann-704393-unsplash.webp 1600w,\n/static/d95f25cddb6a418707b3ced16003c967/de948/gabriel-sollmann-704393-unsplash.webp 5557w","sizes":"(max-width: 800px) 100vw, 800px"}}},"thanks":"Photo by Gabriel Sollmann on Unsplash","reading_time":"1 min 14 sec"},"html":"<h2>The Web Storage API Part 2</h2>\n<p>While sharing a little about The Web Storage API, we checked the Chrome Developer Console and\nfound out that there are some other options to store data in your browser.</p>\n<ul>\n<li>IndexedDB</li>\n<li>Web SQL</li>\n</ul>\n<p>In this article, we will cover the research done to understand these two other options to store\ndata using our browser.</p>\n<h3>IndexedDB</h3>\n<p>There are times when developers need to store a rather large amount of structured data such as\nfiles/blobs. The fact that this can be done for client-side storage is blowing my mind right now.</p>\n<blockquote>\n<p>This feature is available in Web Workers.</p>\n</blockquote>\n<h4>Key concepts and usage</h4>\n<p>IndexedDB is both a transactional database system and a JavaScript-based object-oriented database,\nmeaning it lets you store and retrieve objects that are indexed with a <strong>key</strong>.</p>\n<p>Have in mind these concepts:</p>\n<ul>\n<li>You need to specify the database schema, open a connection to your DB, and then retrieve and update data with <strong>transactions</strong>.</li>\n<li>Combine IndexedDB for storing data offline with <em>Service Workers</em>.</li>\n</ul>\n<blockquote>\n<p><strong>Note</strong>: Like most web storage solutions, IndexedDB follows a <em>same origin policy</em>. So you cannot\naccess stored data across different domains.</p>\n</blockquote>\n<h4>Interfaces</h4>\n<p>The API offers some interfaces to work with for us to interact with the DB properly and also\nit understands what we're trying to do with such objects.</p>\n<p>For us to connect to a DB we call the function <code class=\"language-text\">open()</code> on the <code class=\"language-text\">indexedDB</code> attribute of a\n<code class=\"language-text\">window</code> object, let me show you with a piece of code.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// number one is the version, you can pass any other number</span>\n<span class=\"token comment\">// as parameter there to set your version</span>\nwindow<span class=\"token punctuation\">.</span>indexedDB<span class=\"token punctuation\">.</span><span class=\"token function\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"NAME-OF-YOUR-DATABASE\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// var IDBOpenDBRequest = indexedDB.open(name);</span>\n<span class=\"token comment\">// var IDBOpenDBRequest = indexedDB.open(name, version);</span></code></pre></div>\n<h4>Example of indexedDB</h4>\n<p>Here we can see an example of a todo app using IndexedDB.</p>\n<p><a href=\"http://mdn.github.io/to-do-notifications/\">http://mdn.github.io/to-do-notifications/</a></p>"}},"pageContext":{"id":"8336b248-a02c-5b99-9872-d010cc9d8754"}}}