Last active
December 24, 2018 16:17
-
-
Save shisama/33570f8f4f638892c8b7a960ce263a82 to your computer and use it in GitHub Desktop.
Hello, WorkerDOM! - create element to show 'Hello, World!' in worker with @ampproject/worker-dom.
This file contains 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
setTimeout(() => { | |
const h1 = document.createElement('h1'); | |
h1.textContent = 'Hello World!'; | |
document.getElementById('waiting').remove(); | |
document.body.appendChild(h1); | |
}, 3000); |
This file contains 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
<head> | |
<script src="https://unpkg.com/@ampproject/worker-dom@0.2.8/dist/index.js" nomodule defer></script> | |
</head> | |
<body> | |
<div src="hello.js" id="hello"> | |
<div id="waiting">Waiting...</div> | |
</div> | |
<script type="module"> | |
import {upgradeElement} from 'https://unpkg.com/@ampproject/worker-dom@0.2.8/dist/index.mjs'; | |
upgradeElement(document.getElementById('hello'), 'https://unpkg.com/@ampproject/worker-dom@0.2.8/dist/unminified.worker.mjs'); | |
</script> | |
<script nomodule async=false defer> | |
document.addEventListener('DOMContentLoaded', function() { | |
MainThread.upgradeElement(document.getElementById('upgrade-me'), '/dist/worker.js'); | |
}, false); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment