Fixed JavaScript and CSS evaluation on instant loading

This commit is contained in:
squidfunk 2020-03-09 16:46:22 +01:00
parent 6daac21f65
commit ea29135841
3 changed files with 6 additions and 5 deletions

View File

@ -46,7 +46,8 @@ import {
observeOn,
take,
shareReplay,
share
share,
skip
} from "rxjs/operators"
import {
@ -347,7 +348,7 @@ export function initialize(config: unknown) {
/* Resolve relative links for stability */
for (const selector of [
`link[rel="shortcut icon"]`,
`link[rel="stylesheet"]`
// `link[rel="stylesheet"]` // reduce style computations
])
for (const el of getElements<HTMLLinkElement>(selector))
el.href = el.href

View File

@ -64,8 +64,8 @@ export function patchScripts(
for (const el of els) {
if (el.src || /(^|\/javascript)$/i.test(el.type)) {
const script = document.createElement("script")
const key = el.src ? "src" : "innerText"
script[key] = el[key]
const key = el.src ? "src" : "textContent"
script[key] = el[key]!
el.replaceWith(script)
}
}

View File

@ -64,7 +64,7 @@ let lang: Record<string, string>
export function translate(key: TranslateKey, value?: string): string {
if (typeof lang === "undefined") {
const el = getElementOrThrow("#__lang")
lang = JSON.parse(el.innerText)
lang = JSON.parse(el.textContent!)
}
if (typeof lang[key] === "undefined") {
throw new ReferenceError(`Invalid translation: ${key}`)