Web Storage and Progressive Web Apps (Week 10) Flashcards
What are the limitations of cookies?
- Size limited to approx. 4KB
* Send to the server with each request
What size does HTML5 web storage allow up to?
up to approx. 5MB (depends on browser implementation)
What are the two types of HTML5 web storage?
- Local storage
* Session storage
Are HTML5 web storage options of local and session storage more or less secure than cookies?
No more secure than cookies
What type of storage does local storage offer?
Stores permanent data for your site (i.e., no expiration date)
How does local storage store data?
Stores data in key, value pairs
What are the functions that local storage uses?
Setter and getter functions:
localStorage.setItem(key, value)
localStorage.getItem(key)
What is a local storage object defined for?
a unique origin:
scheme (protocol), host (domain), and port
Why is local storage specific to protocol of the document?
A local storage object is defined for a unique origin:
scheme (protocol), host (domain), and port
E.g., http://example.com has a different local storage object from https://example.com
Explain the local storage code snippet in image #27
1) check if local storage exists i.e. browser supports it
2) set some item in local storage by providing key value pair
3) retrieve the item using the key
4) if the local storage object does not exist, tell user that browser doesn’t support local storage
Explain how local storage is used in Vue.
- Can get local storage values in mounted()
- Should probably not set local storage with each data change, but rather have some mechanism to persist.
- E.g. a ‘save’ button and corresponding Vue method
What type of storage does session storage offer?
Stores temporary data for your site
What happens to the data that is stored using session storage when the browser or tab is closed by user?
Deleted when the session ends
What sort of functions does session storage use?
Same getters and setters as Local storage
i.e.:
sessionStorage.setItem(key, value)
sessionStorage.getItem(key)
Explain the local and session storage code snippet in image #28
1) check if session storage exists i.e. is supported by browser
2) set lastname key value pair using session storage setter
3) alert the user of their first name (retrieved from local storage) and last name (retrieved from session storage)
4) if session storage not supported, alert user.
Explain IndexedDB
✨✨✨
- Web API for creating <strong>indexed NoSQL databases in browser for a web page</strong> to <strong>persistently store data inside a user’s browser.</strong>
- Can create <strong>multiple object stores</strong> - more structured objects, index
- <strong>Primary keys</strong>
- <strong>Indexes</strong> - can build on different elements
- <strong>CRUD (create, read, update, delete) requests</strong> are <strong>asynchronous using promises</strong>
Because it lets you create web applications with rich query abilities <strong>regardless of network availability, your applications can work both online and offline.</strong>
What is an index in IndexedDB?
✨✨✨
a kind of object store for organizing data in another object store (called the reference object store) by an individual property of the data.
What is a transaction in IndexedDB?
A transaction is wrapper around an operation, or group of operations, that ensures database integrity.
What is the CacheStorage API?
✨✨✨
The CacheStorage interface represents the storage for Cache objects.
What does the CacheStorage API store?
Stores pairs of Request and Response objects e.g. HTTP
In terms of the CacheStorage API, how big can the cache be?
Cache can be hundreds of megabytes in size –> LARGE
In terms of the CacheStorage API, how can we access the cache?
const cache = await caches.open(‘my-cache’);
caches -> used here like local storage, provided by cache storage API