From 981bc8ca0aa726f9459cef99168c18cc2173740b Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 19 Apr 2019 19:15:54 +0200 Subject: [PATCH] filter out non .js from http/2 push --- .../src/build-headers-program.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-plugin-netlify/src/build-headers-program.js b/packages/gatsby-plugin-netlify/src/build-headers-program.js index 3d19d96bc9eb8..a1be29ebd36aa 100644 --- a/packages/gatsby-plugin-netlify/src/build-headers-program.js +++ b/packages/gatsby-plugin-netlify/src/build-headers-program.js @@ -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" @@ -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 `) } }