Added preload to custom scripts and styles so they can load earlier

This commit is contained in:
Yann Le Vagueres 2023-09-10 20:43:04 +02:00
parent 08e3164e84
commit d8f6a59f17
No known key found for this signature in database
GPG Key ID: EF41B255CD47BC5E
2 changed files with 5 additions and 2 deletions

View File

@ -17,6 +17,7 @@ export default async function handler(req, res) {
if (!['custom.css', 'custom.js'].includes(relativePath))
{
res.status(422).end('Unsupported file')
return // do not continue in the function
}
const filePath = path.join(CONF_DIR, relativePath);

View File

@ -313,14 +313,16 @@ function Home({ initialSettings }) {
<meta name="theme-color" content={themes[settings.color || "slate"][settings.theme || "dark"]} />
</Head>
<style alt="custom">
<link rel="preload" href="/api/config/custom.css" as="fetch" crossorigin="anonymous" />
<style data-name="custom.css">
<FileContent path="custom.css"
loadingValue="/* Loading custom CSS... */"
errorValue="/* Failed to load custom CSS... */"
emptyValue="/* No custom CSS */"
/>
</style>
<script alt="custom">
<link rel="preload" href="/api/config/custom.js" as="fetch" crossorigin="anonymous" />
<script data-name="custom.js">
<FileContent path="custom.js"
loadingValue="/* Loading custom JS... */"
errorValue="/* Failed to load custom JS... */"