perf: do preconnect instead of prefetch for instance (#1368)

This commit is contained in:
Nolan Lawson 2019-08-03 12:02:06 -07:00 committed by GitHub
parent c1b8a99dbe
commit 000d725240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -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)
}