From 4561c4e192a39fc643d4c4fc3db055d830492334 Mon Sep 17 00:00:00 2001 From: Daniel Erat Date: Sat, 17 Aug 2019 15:59:29 -0400 Subject: [PATCH] Load Firebase asynchronously. (#77) Update src/firebase/index.ts to export getFirebase, getAuth, getFirestore, getFunctions, and getFirebaseUI functions that load the corresponding Firebase modules asynchronously. This lets webpack create separate chunks for each piece of Firebase, reducing the app entrypoint from 1.12 MiB to 593 KiB. It also improves Lighthouse measurements for the login page on a simulated 3G network with 4x CPU slowdown: First Contentful Paint: 3.1s -> 2.4s Time to Interactive: 3.5s -> 3.0s First Meaningful Paint: 3.2s -> 2.4s First CPU Idle: 3.3s -> 2.9s I'd expected an improvement here, since the login page doesn't depend on Firestore. It's harder to tell if there's a benefit on the other pages. They all require login, which means that "Clear Storage" needs to be unchecked in Chrome's Dev Tools Audit tab, which I think means that the cache is preserved, so download time doesn't get measured. See https://github.com/GoogleChrome/lighthouse/issues/2599 for more discussion of this. It stands to reason that there would be less benefit there, though, since all of those pages require both the auth and Firestore modules to be loaded before they can do anything meaningful. --- src/App.vue | 29 ++++------ src/components/ClimbDropdown.test.ts | 2 +- src/components/RouteList.test.ts | 2 +- src/components/Toolbar.vue | 14 +++-- src/firebase/auth.ts | 20 ------- src/firebase/firestore.ts | 20 ------- src/firebase/functions.ts | 11 ---- src/firebase/index.ts | 65 ++++++++++++++++++++++ src/firebase/init.ts | 5 +- src/firebase/mock.ts | 20 +++++-- src/log/index.ts | 15 ++--- src/main.ts | 20 ++++--- src/mixins/UserLoader.ts | 66 +++++++++++++++++----- src/router/index.ts | 30 +++++----- src/views/Login.vue | 83 +++++++++++++++------------- src/views/Profile.test.ts | 10 +++- src/views/Profile.vue | 59 ++++++++++---------- src/views/Routes.test.ts | 9 ++- src/views/Routes.vue | 50 ++++++++++------- src/views/Statistics.test.ts | 8 ++- src/views/Statistics.vue | 17 +++--- 21 files changed, 320 insertions(+), 235 deletions(-) delete mode 100644 src/firebase/auth.ts delete mode 100644 src/firebase/firestore.ts delete mode 100644 src/firebase/functions.ts create mode 100644 src/firebase/index.ts diff --git a/src/App.vue b/src/App.vue index d8df3b5..9e29aa2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,7 +4,7 @@