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', () => { })] }, [/
.*