The Solution of Script Error Problem

Time:2019-10-10

problem

When third-party scripts report errors, they do not expose detailed error information because of cross-domain problems. Instead, they are uniform.Script error

The Solution of Script Error Problem

What we have come across ispageandjsThe secondary domain name is the same, and it is set up.document.domainChrome browsers can display detailed error stacks; however, many mobile browsers still doScript error

solution

The CDN we use is Ali Yun. In fact, he has given the solution to this problem.

After reading, we know that just add the crossorigin attribute to the script tag, and the effect is as follows

The Solution of Script Error Problem

Specific methods

Our project useswebpackPlug-ins that modify HTML should be used by everyonehtml-webpack-pluginThe derivative plug-in of this plug-inscript-ext-html-webpack-pluginTo meet our needs.

plugins: [
  ....
  new HtmlWebpackPlugin({
    inject: true,
    template: paths.appHtmlProd,
  }),
  new ScriptExtHtmlWebpackPlugin({
    custom: {
      test: /\.js$/,
      attribute: 'crossorigin',
      value: 'anonymous'
    }
  }),
  ...
]

Recommended Today

Easy to use performance testing tool – Glances

I often use htop tool to perform performance test on the host. But it can only manage. And briefly display process and CPU and memory usage information; Glances are better performance testing tools. Htop can also display disk IO net and other information. There is also a web UI and ipc schema. This tool is […]