From 97f9fb9a68e4d3c3c9453296c352e831f7546937 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Tue, 17 Mar 2020 22:09:05 +0100 Subject: [PATCH] fix: load script files before style files files in defer script loading mode --- index.js | 5 ++++- spec/basic.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2b4af9d9..e6779f5f 100644 --- a/index.js +++ b/index.js @@ -833,7 +833,10 @@ class HtmlWebpackPlugin { if (scriptTarget === 'body') { result.bodyTags.push(...assetTags.scripts); } else { - result.headTags.push(...assetTags.scripts); + // If script loading is blocking add the scripts to the end of the head + // If script loading is non-blocking add the scripts infront of the css files + const insertPosition = this.options.scriptLoading === 'blocking' ? result.headTags.length : assetTags.meta.length; + result.headTags.splice(insertPosition, 0, ...assetTags.scripts); } return result; } diff --git a/spec/basic.spec.js b/spec/basic.spec.js index 571fe149..5d706c47 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -2282,4 +2282,26 @@ describe('HtmlWebpackPlugin', () => { })] }, [/.*