Skip to content

Commit

Permalink
Trying to find workaround for #46
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Nov 22, 2017
1 parent b0de434 commit 7b7ba6f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ const defaultOptions = {
preloadImages: false,
// add async true to scripts and move them to the header, to start download earlier
// can use <link rel="preload"> instead
asyncScriptTags: false,
asyncScriptTags: false, //this will break reactLoadableTrick
//# another feature creep
// tribute to Netflix Server Side Only React https://twitter.com/NetflixUIE/status/923374215041912833
// but this will also remove code which registers service worker
removeScriptTags: false
removeScriptTags: false,
reactLoadableTrick: false
};

/**
Expand Down Expand Up @@ -330,22 +331,19 @@ const fixWebpackChunksIssue = ({ page, basePath }) => {
const chunkRegexp = /\.[\w]{8}\.chunk\.js/;
const chunkSripts = localScripts.filter(x => chunkRegexp.test(x.src));

const createLink = x => {
const linkTag = document.createElement("link");
linkTag.setAttribute("rel", "preload");
linkTag.setAttribute("as", "script");
linkTag.setAttribute("href", x.src.replace(basePath, ""));
mainScript.parentNode.insertBefore(linkTag, mainScript.nextSibling);
};

// if (reactLoadableTrick) {
const scriptTag = document.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.text = "window.bootReactSnapApp && window.bootReactSnapApp();";
// }
mainScript.parentNode.insertBefore(scriptTag, mainScript.nextSibling);
for (let i = chunkSripts.length - 1; i >= 0; --i) {
const x = chunkSripts[i];
if (x.parentElement && mainScript.parentNode) {
x.parentElement.removeChild(x);
createLink(x);
mainScript.parentNode.insertBefore(x, mainScript.nextSibling);
}
}
createLink(mainScript);
}, basePath);
};

Expand Down

0 comments on commit 7b7ba6f

Please sign in to comment.