Skip to content

Commit

Permalink
Merge pull request #576 from tomkelsey/preload-styles-first
Browse files Browse the repository at this point in the history
Sort preload assets so that styles are first
  • Loading branch information
theKashey authored Jun 5, 2020
2 parents 5da0c38 + 41f862c commit c618c41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ function extensionToScriptType(extension) {
}

function getAssets(chunks, getAsset) {
return uniqBy(flatMap(chunks, chunk => getAsset(chunk)), 'url')
return uniqBy(
flatMap(chunks, chunk => getAsset(chunk)),
'url',
)
}

function handleExtraProps(asset, extraProps) {
Expand Down Expand Up @@ -411,6 +414,7 @@ class ChunkExtractor {
const preloadAssets = this.getChunkChildAssets(chunks, 'preload')
const prefetchAssets = this.getChunkChildAssets(chunks, 'prefetch')
return [...mainAssets, ...preloadAssets, ...prefetchAssets]
.sort(a => (a.scriptType === 'style' ? -1 : 0))
}

getLinkTags(extraProps = {}) {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6531,6 +6531,13 @@ make-dir@^2.0.0, make-dir@^2.1.0:
pify "^4.0.1"
semver "^5.6.0"

make-dir@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
integrity sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==
dependencies:
semver "^6.0.0"

make-fetch-happen@^5.0.0:
version "5.0.2"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-5.0.2.tgz#aa8387104f2687edca01c8687ee45013d02d19bd"
Expand Down

0 comments on commit c618c41

Please sign in to comment.