2

I want to defer parsing of scripts that are generate as a result of transpiling during build. I have added async to all the other tags on my index.html page. However, since the main js file is inject into page during build, it becomes harder.

Is there a way to tell babel/react-scripts to add the async attribute to the injected js tag?

2 Answers 2

1

I just ran into this issue recently as well when starting out with create-react-app. However, my problem was in the context of pre-rendering the pages statically. I am using react-snap which has the following configuration option:

"reactSnap": {
  "asyncScriptTags": true
}

This adds the async attribute to the main.js script tag of the generated pages. Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi! I am facing same issue with create-react-app scaffold tool, can you be more specific? So you install that package with npm and add this config to package.json and that's all? Thank you :)
Yes, that should be all.
1

I solved the same problem ejecting react-scripts and modifying the configuration files.

Basically you install this new webpack plugin: Script Extension for HTML Webpack Plugin. And then you add this snippet to both dev and prod webpack configurations, within plugins array:

new ScriptExtHtmlWebpackPlugin({
    defaultAttribute: 'async'
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.