javascript – Что лучше:,, или localStorage?


What is better to use Google Сhrome Extention extensions for storing data, and what is the fundamental difference between / / localStorage , taking into account the possibility of obtaining this data in any tab?

Preferably with an example, please.


localStorage is HTML5 data storage. Documentation

localStorage stores data in the form: name = value (value is a string), that is, it does not allow storing compound objects. Moreover, types like true , false will be stored as "true" and "false" . Data are accessed using a synchronous method:

var x = localStorage.x;
var x = localStorage['x'];
var x = localStorage.getItem('x'); – extension data storage. Allows to store objects, unlike localStorage . Data is accessed asynchronously. Allows you to "listen" to changes in variables. Storage documentation – works like , but stores data on the server, synchronized by google account between all authorized browsers.

For extensions, it is preferable to use local / sync – depends on your needs

Scroll to Top