Published
Edited
Aug 30, 2021
Insert cell
md`# Local storage test`
Insert cell
md`It's probably best to use the more official https://observablehq.com/@mbostock/safe-local-storage !`
Insert cell
a = button({'value': 'put "foo" in localStorage'})
Insert cell
{
a.onclick = () => localStorage.setItem('value', 'foo')
b.onclick = () => localStorage.setItem('value', undefined)
}
Insert cell
b = button({value: 'clear localStorage'})
Insert cell
md`What's in localStorage?`
Insert cell
localStorage.getItem('value')
Insert cell
manifest = ({
"name": "localStorage test",
"short_name": "lS test",
"description": "A localStorage test.",
"display": "standalone",
"scope": "/",
"icons": []
})
Insert cell
function createWorker(s, cb) {
const worker = new window.Worker(
window.URL.createObjectURL(
new Blob(
[`
self.onmessage = function(e){
let result = eval("("+e.data.script+"())")
self.postMessage(result);
}`
],
{
type: "text/javascript"
}
)
)
);
if (typeof cb == "function") {
cb(worker);
}
}
Insert cell
caches
Insert cell
manifest_url = Files.url(manifest_json)
Insert cell
btoa(manifest_json)
Insert cell
document.head.children[3].outerHTML
Insert cell
window.foo = document.head.appendChild(html`<link rel="manifest" href="${'data:application/json;base64;' + btoa(JSON.stringify(manifest))}">`)
Insert cell
manifest_json = new File([JSON.stringify(manifest)], 'manifest.json')
Insert cell
import {button} from '@jashkenas/inputs'
Insert cell
performance.getEntriesByType("resource")
Insert cell
performance.getEntriesByType("resource").map(e => e.name)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more