Skip to content

Instantly share code, notes, and snippets.

@lukeed
Last active April 2, 2019 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeed/571fa3d77c5f116b6d2c5cd265b663b8 to your computer and use it in GitHub Desktop.
Save lukeed/571fa3d77c5f116b6d2c5cd265b663b8 to your computer and use it in GitHub Desktop.
<!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>
import csz from 'https://unpkg.com/csz@0.1.2/index.js';
import htm from 'https://unpkg.com/htm@2.1.1/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/es-react@16.8.30/index.js'
: 'https://unpkg.com/es-react-production@16.8.30/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
)
}
@lukeed
Copy link
Author

lukeed commented Apr 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment