Monday, April 1, 2019

KV Storage

localStorage is...

  • Good! It's an incredibly easy API to use.
  • localStorage.setItem('name', 'Chris'); let name = localStorage.getItem('name');
    
  • Bad! Philip Walton explains why:

localStorage is a synchronous API that blocks the main thread, and any time you access it you potentially prevent your page from being interactive.

Chrome has an idea (here's the proposal) for reinventing it. Ultimately the API is even simpler:

import { storage } from 'std:kv-storage';
storage.set('name', 'Chris');
storage.get('name');

But! It's async, so I can use await before I do those things without blocking anything. This demo will work in Chrome Canary right now:

See the Pen
eXadrq
by Chris Coyier (@chriscoyier)
on CodePen.

What in all heck is up with this line?

import { storage } from 'std:kv-storage';

They are calling it a "built-in module." In other words, something you can import but it makes no network request because it's built into the browser. Pretty interesting approach.

Philip continues:

Not exposing built-in modules globally has a lot of advantages: they won't add any overhead to starting up a new JavaScript runtime context (e.g. a new tab, worker, or service worker), and they won't consume any memory or CPU unless they're actually imported. Furthermore, they don't run the risk of naming collisions with other variables defined in your code.

This is built on top of indexedDB, so if you're playing with it and need to clear the values or whatever, you do it there (DevTools > Application > Storage > IndexedDB). It'll be fascinating to see if this catches on and whether new JavaScript features are shipped as built-in modules. I have no sense of whether other browsers think this is a good idea or not.

Direct Link to ArticlePermalink

The post KV Storage appeared first on CSS-Tricks.

from CSS-Tricks https://developers.google.com/web/updates/2019/03/kv-storage

KV Storage Find more on: The Instant Web Site Tools Blog

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage/

KV Storage Read more on: The Instant Web Site Tools Blog

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-2/

KV Storage was originally seen on Instant Web Site Tools.com Blog

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-3/

KV Storage was first seen on Instant Web Site Tools Blog

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-4/

KV Storage was initially published to https://www.instant-web-site-tools/

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-5/

The article KV Storage is available on http://www.instant-web-site-tools/

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-6/

KV Storage was first published on Instant Web Site Tools

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-7/

KV Storage See more on: Instant Web Site Tools Blog

From https://www.instant-web-site-tools.com/2019/04/02/kv-storage-8/

The following blog article KV Storage See more on: www.instant-web-site-tools



source https://www.instant-web-site-tools.com/2019/04/02/kv-storage-9/

No comments:

Post a Comment

40+ Best Minimal Logo Design Templates

Minimalist logo design is an art. How can you convey your brand with a professional logo, but keep the simplicity of a minimal, clean, and s...