Skip to content

Instantly share code, notes, and snippets.

@gbakernet
gbakernet / app.js
Last active July 2, 2018 10:46 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4 with quick and dirty SSR support
// Preserve the server render markup
// This has to run before the root render
let preservedMarkup = {}
if (typeof document !== "undefined") {
[...document.querySelectorAll("[data-async-component]")].map(node =>
preservedMarkup[node.getAttribute("data-async-component")] = node.innerHTML
)
}
// getComponent is a function that returns a promise for a component