Skip to content

Commit

Permalink
[fix] load CSS before JS preloads
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Dec 29, 2021
1 parent 43b0f5a commit d138efe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-frogs-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] load CSS before JS preloads
7 changes: 5 additions & 2 deletions packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ export async function render_response({
? `<style amp-custom>${Array.from(styles).concat(rendered.css.code).join('\n')}</style>`
: ''
: [
...Array.from(js).map((dep) => `<link rel="modulepreload" href="${options.prefix}${dep}">`),
...Array.from(css).map((dep) => `<link rel="stylesheet" href="${options.prefix}${dep}">`)
// From https://web.dev/priority-hints/:
// Generally, preloads will load in the order the parser gets to them for anything above "Medium" priority
// Thus, we should list CSS first
...Array.from(css).map((dep) => `<link rel="stylesheet" href="${options.prefix}${dep}">`),
...Array.from(js).map((dep) => `<link rel="modulepreload" href="${options.prefix}${dep}">`)
].join('\n\t\t');

/** @type {string} */
Expand Down

0 comments on commit d138efe

Please sign in to comment.