Skip to content

Commit

Permalink
filter out non .js from http/2 push
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Apr 19, 2019
1 parent 67b6819 commit 981bc8c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/gatsby-plugin-netlify/src/build-headers-program.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from "lodash"
import { writeFile, existsSync } from "fs-extra"
import { parse } from "path"
import kebabHash from "kebab-hash"
import { HEADER_COMMENT } from "./constants"

Expand Down Expand Up @@ -41,15 +42,18 @@ function createScriptHeaderGenerator(manifest, pathPrefix) {
return null
}

// If it's an array, return a string containing all the files
if (_.isArray(chunk)) {
return chunk
.map(script => linkTemplate(`${pathPrefix}/${script}`))
.join(`\n `)
}

// Always add starting slash, as link entries start with slash as relative to deploy root
return linkTemplate(`${pathPrefix}/${chunk}`)
// convert to array if it's not already
const chunks = _.isArray(chunk) ? chunk : [chunk]

return chunks
.filter(script => {
const parsed = parse(script)
// handle only .js, .css content is inlined already
// and doesn't need to be pushed
return parsed.ext === `.js`
})
.map(script => linkTemplate(`${pathPrefix}/${script}`))
.join(`\n `)
}
}

Expand Down

0 comments on commit 981bc8c

Please sign in to comment.