Module scripts loaded with low priority when compiled
#6,981 opened on Sep 23, 2021
Repository metrics
- Stars
- (44,030 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Native module scripts (e.g. <script type="module">) are typically loaded by browsers with high priority. However, when targeting browsers without native support, Parcel inserts <script defer nomodule> tags, which are loaded with low priority. See https://addyosmani.com/blog/script-priorities/.
With that said, these scripts still need the defer attribute to emulate the execution timing of native modules. One workaround to boost priority of deferred scripts is to also insert a <link rel="preload" as="script"> into the document head with an href with the same value as the script's src.
We should consider adding these link tags as well when including js targeted at these environments.
Related: #6980