From 87fcc2dc672e09e543aeb6c5f48efaab350bd007 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Fri, 2 Jul 2021 19:41:11 +0200 Subject: [PATCH] Use smaller bundles again Turns out that compiling a large bundle is really slow and apparently also not parallelized. I thought it might make sense to not split the bundle to not create any unnecessary requests. But JavaScript is apparently really slow to compile, so any sort of parallelization we can get definitely outweighs the slight cost to the additional requests. --- src/index.tsx | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/main.tsx | 51 ------------------------------------------- 2 files changed, 59 insertions(+), 52 deletions(-) delete mode 100644 src/main.tsx diff --git a/src/index.tsx b/src/index.tsx index e41faff..d6a0139 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,5 +3,63 @@ if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) { } import "./css/main.scss"; -import("./main"); import("./css/font-awesome.css"); + +const [ + { LiveSplit }, + React, + ReactDOM, + { toast, ToastContainer }, +] = await Promise.all([ + import("./ui/LiveSplit"), + import("react"), + import("react-dom"), + import("react-toastify"), +]); + +try { + const { + splits, + splitsKey, + layout, + hotkeys, + layoutWidth, + } = await LiveSplit.loadStoredData(); + + try { + ReactDOM.render( +
+ + +
, + document.getElementById("base"), + ); + } catch (_) { + alert(`Couldn't load LiveSplit One. \ +You may be using a browser that is not up to date. \ +Please update your browser or your iOS version and try again. \ +Another reason might be that a browser extension, such as an adblocker, \ +is blocking access to important scripts.`); + } +} catch (e) { + if (e.name === "InvalidStateError") { + alert(`Couldn't load LiveSplit One. \ +You may be in private browsing mode. \ +LiveSplit One cannot store any splits, layouts, or other settings because of the limitations of the browser's private browsing mode. \ +These limitations may be lifted in the future. \ +To run LiveSplit One for now, please disable private browsing in your settings.\n`); + } +} diff --git a/src/main.tsx b/src/main.tsx deleted file mode 100644 index 5a428b2..0000000 --- a/src/main.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { LiveSplit } from "./ui/LiveSplit"; -import * as React from "react"; -import * as ReactDOM from "react-dom"; -import { toast, ToastContainer } from "react-toastify"; - -try { - const { - splits, - splitsKey, - layout, - hotkeys, - layoutWidth, - } = await LiveSplit.loadStoredData(); - - try { - ReactDOM.render( -
- - -
, - document.getElementById("base"), - ); - } catch (_) { - alert(`Couldn't load LiveSplit One. \ -You may be using a browser that is not up to date. \ -Please update your browser or your iOS version and try again. \ -Another reason might be that a browser extension, such as an adblocker, \ -is blocking access to important scripts.`); - } -} catch (e) { - if (e.name === "InvalidStateError") { - alert(`Couldn't load LiveSplit One. \ -You may be in private browsing mode. \ -LiveSplit One cannot store any splits, layouts, or other settings because of the limitations of the browser's private browsing mode. \ -These limitations may be lifted in the future. \ -To run LiveSplit One for now, please disable private browsing in your settings.\n`); - } -}