Fix: async property of scripts is not assigned properly
This fix addresses a problem that happens when trying to set the async attribute of a script tag.
Intuitively, setting the async attribute on the tag should also set the the element async property. However this is not the case.
This not a bug but part of the specification.
The async attribute is used only by the HTML/XML parser when the page is initially loaded, but it's ignored on dynamic scripts, which are async by default (you can check the section about "force-async": https://www.w3.org/TR/2014/PR-html5-20140916/scripting-1.html ).
For this reason script.setAttribute('async', value) will not work as expected.
In order to actually change the async behavior of the tag, the property must be set directly with script.async = value.
Setting async=false is particularly useful to maintain the execution order of dynamic scripts.
Inside issue #419 someone actually suggested this solution, but when I tried some code like the following one the tags executed out of order most of the time.
<Helmet>
<script async={false} src="big-file.js" />
<script async={false} src="small-file.js" />
</Helmet>
Related issues: #419
is this going to be merged?
Bump. When will this be merged?
I'm going to leave here the patch file for anyone who might need it: https://pastebin.com/fmHGfSFb
You can use patch-package to apply it in your project.