From a2c5175d14b322062f8fc07b11a6a45f1d5aba4f Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 26 Jun 2020 14:47:02 +0300 Subject: [PATCH 1/3] add basic preloading for nodeinfo/config --- src/boot/after_store.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 0db03547..0c213ea3 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -8,9 +8,34 @@ import backendInteractorService from '../services/backend_interactor_service/bac import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js' import { applyTheme } from '../services/style_setter/style_setter.js' +let staticInitialResults = null + +const parsedInitialResults = () => { + if (!document.getElementById('initial-results')) { + return null + } + if (!staticInitialResults) { + staticInitialResults = JSON.parse(document.getElementById('initial-results').textContent) + } + return staticInitialResults +} + +const preloadFetch = async (request) => { + const data = parsedInitialResults() + if (!data || !data[request]) { + return window.fetch(request) + } + const requestJson = atob(data[request]) + return { + ok: true, + json: () => JSON.parse(requestJson), + text: () => requestJson + } +} + const getStatusnetConfig = async ({ store }) => { try { - const res = await window.fetch('/api/statusnet/config.json') + const res = await preloadFetch('/api/statusnet/config.json') if (res.ok) { const data = await res.json() const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey, safeDMMentionsEnabled } = data.site @@ -132,7 +157,7 @@ const getTOS = async ({ store }) => { const getInstancePanel = async ({ store }) => { try { - const res = await window.fetch('/instance/panel.html') + const res = await preloadFetch('/instance/panel.html') if (res.ok) { const html = await res.text() store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html }) @@ -195,7 +220,7 @@ const resolveStaffAccounts = ({ store, accounts }) => { const getNodeInfo = async ({ store }) => { try { - const res = await window.fetch('/nodeinfo/2.0.json') + const res = await preloadFetch('/nodeinfo/2.0.json') if (res.ok) { const data = await res.json() const metadata = data.metadata From a8cb5e71d9ab3025786838d7123ad676a1e7fb66 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Sat, 27 Jun 2020 12:32:01 +0300 Subject: [PATCH 2/3] don't block ui with stickers or tos --- src/boot/after_store.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 01074b8c..de7c3ef4 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -340,17 +340,18 @@ const afterStoreSetup = async ({ store, i18n }) => { } // Now we can try getting the server settings and logging in + // Most of these are preloaded into the index.html so blocking is minimized await Promise.all([ checkOAuthToken({ store }), - getTOS({ store }), getInstancePanel({ store }), - getStickers({ store }), getNodeInfo({ store }), getInstanceConfig({ store }) ]) // Start fetching things that don't need to block the UI store.dispatch('fetchMutes') + getTOS({ store }) + getStickers({ store }) const router = new VueRouter({ mode: 'history', From 46cf50a4d653b9f9b2b9d3f13d88a7af7b950d18 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Sat, 27 Jun 2020 12:59:24 +0300 Subject: [PATCH 3/3] rename variable requestJson when it's not actually json --- src/boot/after_store.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index de7c3ef4..1796eb1b 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -25,11 +25,11 @@ const preloadFetch = async (request) => { if (!data || !data[request]) { return window.fetch(request) } - const requestJson = atob(data[request]) + const requestData = atob(data[request]) return { ok: true, - json: () => JSON.parse(requestJson), - text: () => requestJson + json: () => JSON.parse(requestData), + text: () => requestData } }