Html-webpack-plugin: Feature Request: type="text/javascript" is not needed on script tag

Created on 15 Jan 2018  路  4Comments  路  Source: jantimon/html-webpack-plugin

Version: 2.30.1

I wasn't sure if this was a feature request or a bug, it could go either way.

On line 479 of index.js

// Turn script files into script tags
  var scripts = assets.js.map(function (scriptPath) {
    return {
      tagName: 'script',
      closeTag: true,
      attributes: {
479        type: 'text/javascript',
        src: scriptPath
      }
    };
  });

The type attribute should not be set. This is an obsolete attribute and HTML linters will complain about it, and rightly so. I could not find any documentation that indicated a way to prevent this.

It appears that all that is required to fix it is to remove line 479. I guess alternatively there could be an option to disable this or it could be tied to the doctype.

Most helpful comment

A possible workaround is to use removeScriptTypeAttributes of HTMLMinifier, see here.

new HtmlWebpackPlugin({
  filename: 'app.html',
  template: 'app/app.ejs',
  minify: {
    removeScriptTypeAttributes: true,
  },
}),

In this case, ALL type="text/javascript" will be removed, whether exists before or injected.

All 4 comments

Pedant mode: the attribute itself isn't obselete, it's just obselete in this instance 馃槞

Relevant link is here confirming what @markfaine is saying: https://dev.w3.org/html5/spec-preview/the-script-element.html#attr-script-type

I do agree with making the change though, I wonder though if it should be toggleable via options rather than just be deleted, for legacy support? Not just for older browsers/liners but also the myriad of libraries that may (rightly or wrongly) require this atribute to be set.

A possible workaround is to use removeScriptTypeAttributes of HTMLMinifier, see here.

new HtmlWebpackPlugin({
  filename: 'app.html',
  template: 'app/app.ejs',
  minify: {
    removeScriptTypeAttributes: true,
  },
}),

In this case, ALL type="text/javascript" will be removed, whether exists before or injected.

@b1f6c1c4, thanks, I didn't realize that existed. That's a great workaround in the meantime and I'm already using HTMLMinifier anyway. I'm surprised I didn't notice that option myself.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings