Last active
April 2, 2019 01:51
-
-
Save lukeed/571fa3d77c5f116b6d2c5cd265b663b8 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Perflink | JS Benchmarks</title> | |
<meta | |
name="description" | |
content="JavaScript performance benchmarks that you can share via URL." | |
/> | |
<meta | |
name="viewport" | |
content="width=device-width, initial-scale=1, shrink-to-fit=no" | |
/> | |
<script> | |
;(function() { | |
var redirect = sessionStorage.redirect | |
delete sessionStorage.redirect | |
if (redirect && redirect != location.href) | |
history.replaceState(null, null, redirect) | |
})() | |
</script> | |
<link rel="stylesheet" href="/index.css" /> | |
<link rel="stylesheet" href="/library/prism.css" /> | |
<script src="https://unpkg.com/shimport"></script> | |
<script defer type="module" src="index.js"></script> | |
<script defer src="/library/prism.js"></script> | |
</head> | |
<body></body> | |
</html> |
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
import csz from 'https://unpkg.com/[email protected]/index.js'; | |
import htm from 'https://unpkg.com/[email protected]/dist/htm.mjs'; | |
// Leverage built-in URL parsing to convert | |
// relative URLs into fully qualified links | |
function href(url, tmp) { | |
(tmp = document.createElement('a')).href = url; | |
return tmp.href; | |
} | |
// Call the native `import` if it exists. | |
// This method isn't parsed initially & throws | |
// "safely" in Firefox w/o killing the whole app. | |
function shim(url) { | |
try { | |
return new Function(`return import('${url}')`).call(); | |
} catch (err) { | |
return __shimport__.load(href(url)); | |
} | |
} | |
shim(location.hostname === 'localhost' | |
? 'https://unpkg.com/[email protected]/index.js' | |
: 'https://unpkg.com/[email protected]/index.js').then(app); | |
function app({ React, ReactDOM }) { | |
window.React = React | |
window.css = csz | |
window.html = htm.bind(React.createElement) | |
const Fallback = html` | |
<div></div> | |
` | |
const Route = { | |
'/': React.lazy(() => shim('./routes/home/index.js')), | |
'*': React.lazy(() => shim('./routes/notfound/index.js')), | |
} | |
ReactDOM.render( | |
html` | |
<${React.Suspense} fallback=${Fallback}> | |
<${Route[location.pathname] || Route['*']} /> | |
<//> | |
`, | |
document.body | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PR: lukejacksonn/perflink#8