From 000d72524015d2a771f1273294a257399a1f1191 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 3 Aug 2019 12:02:06 -0700 Subject: [PATCH] perf: do preconnect instead of prefetch for instance (#1368) --- src/inline-script/inline-script.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/inline-script/inline-script.js b/src/inline-script/inline-script.js index 741fbd8b..044aab38 100644 --- a/src/inline-script/inline-script.js +++ b/src/inline-script/inline-script.js @@ -22,13 +22,10 @@ const { const theme = (instanceThemes && instanceThemes[currentInstance]) || DEFAULT_THEME if (currentInstance) { - // Do prefetch if we're logged in, so we can connect faster to the other origin. - // Note that /api/v1/instance is basically the only URL that doesn't require credentials, - // which is why we can do this. Also we do end up calling this on loading the home page, - // so it's not a wasted request. + // Do preconnect if we're logged in, so we can connect faster to the other origin. let link = document.createElement('link') - link.setAttribute('rel', 'prefetch') - link.setAttribute('href', `${basename(currentInstance)}/api/v1/instance`) + link.setAttribute('rel', 'preconnect') + link.setAttribute('href', basename(currentInstance)) link.setAttribute('crossorigin', 'anonymous') document.head.appendChild(link) }