Created
March 29, 2023 17:40
-
-
Save prof3ssorSt3v3/d451a6a029f4e1c91dbd1cef9b79b380 to your computer and use it in GitHub Desktop.
Code from Video about Persistent Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
<style> | |
html { | |
color-scheme: dark light; | |
font-family: system-ui; | |
font-size: 20px; | |
font-weight: 300; | |
line-height: 1.7; | |
} | |
body { | |
margin: 4rem; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<h1>Persistent Storage</h1> | |
</header> | |
<main> | |
<ul> | |
<li>Cookies</li> | |
<li>LocalStorage | SessionStorage</li> | |
<li>Cache API</li> | |
<li>IndexedDB</li> | |
<li>ServiceWorkers</li> | |
<li>FileSystem API*</li> | |
<li><s>WebSQL</s></li> | |
<li><s>AppCache</s></li> | |
</ul> | |
<p>Chrome will examine the following to decide:</p> | |
<ul> | |
<li>Level of user engagement?</li> | |
<li>Notifications allowed?</li> | |
<li>Bookmarked or installed?</li> | |
</ul> | |
</main> | |
<script> | |
const log = console.log; | |
//working with Persistent Storage | |
if (navigator.storage && navigator.storage.persisted) { | |
//always feature detect | |
// persisted() - has this been marked as persisted | |
// persist() - permissions request | |
navigator.storage.persisted().then((wellWasIt) => { | |
log({ wellWasIt }); | |
navigator.storage.persist().then((allowed) => { | |
log({ allowed }); | |
}); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment