Skip to content

Commit

Permalink
either preload OR inline CSS (#6009)
Browse files Browse the repository at this point in the history
* either preload OR inline

* Make sure all assets added
  • Loading branch information
thescientist13 authored and KyleAMathews committed Jun 21, 2018
1 parent 176e947 commit 7242818
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions packages/gatsby/src/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export default (pagePath, callback) => {
return { rel: `preload`, name: chunk }
})

namedChunkGroups[s].assets.forEach(asset =>
chunks.push({ rel: `preload`, name: asset })
)

const childAssets = namedChunkGroups[s].childAssets
for (const rel in childAssets) {
chunks = merge(
Expand Down Expand Up @@ -239,28 +243,32 @@ export default (pagePath, callback) => {
.slice(0)
.reverse()
.forEach(style => {
// Add <link>s for styles.
headComponents.push(
<link
as="style"
rel={style.rel}
key={style.name}
href={urlJoin(pathPrefix, style.name)}
/>
)

headComponents.unshift(
<style
type="text/css"
data-href={urlJoin(pathPrefix, style.name)}
dangerouslySetInnerHTML={{
__html: fs.readFileSync(
join(process.cwd(), `public`, style.name),
`utf-8`
),
}}
/>
)
// Add <link>s for styles that should be prefetched
// otherwise, inline as a <style> tag

if (style.rel === `prefetch`) {
headComponents.push(
<link
as="style"
rel={style.rel}
key={style.name}
href={urlJoin(pathPrefix, style.name)}
/>
)
} else {
headComponents.unshift(
<style
type="text/css"
data-href={urlJoin(pathPrefix, style.name)}
dangerouslySetInnerHTML={{
__html: fs.readFileSync(
join(process.cwd(), `public`, style.name),
`utf-8`
),
}}
/>
)
}
})

// Add page metadata for the current page
Expand Down

0 comments on commit 7242818

Please sign in to comment.