numical / script-ext-html-webpack-plugin

Enhances html-webpack-plugin functionality with different deployment options for your scripts including 'async', 'preload', 'prefetch', 'defer', 'module', custom attributes, and inlining.
MIT License
588 stars 105 forks source link

Duplicate entry of script files which are configured for preloading #22

Closed pratyushj closed 7 years ago

pratyushj commented 7 years ago

This is my webpack configuration for ScriptExtHtmlWebpackPlugin

 new ScriptExtHtmlWebpackPlugin({
        async : [/app/],
        preload : [/manifest/,/vendor\.bundle/]
    }),

I want to preload my vendor files and asynchronously load my app build file. But the html generated has the entry for manifest and vendor files twice, one for preload hint and the other as a script tag

screen shot 2017-05-22 at 9 01 40 am

Prior apologies if the configuration has been done wrong ).

numical commented 7 years ago

Hi Pratyush,

ScriptExt is doing the right thing. There are two seperate instructions going on - there are the core <script> elements that instruct the browser to download and then run their defined javascripts; and there are preload hints that suggest to the browser that it may want to download some resources (in this case the self-same javascripts) for later use.
So you can read you html as the following set of instrctions: (though remember, in reality, a modern browser will paralllize most of this):

The net effect is that the page will load and accept user input before your app is loaded so the user could see a blank screen for a few moments. If you are planning to add some html for this prior state, that's great - else I wouldn't bother with the async. Moreover, as your configuration currently stands, I don't think the preload will offer you any benefit as nothing of long duration happens before the <script> tags are processed. In other words, I think you might not need ScriptExt at all!