parcel-bundler/parcel

Module scripts loaded with low priority when compiled

Open

#6,981 opened on Sep 23, 2021

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (44,030 stars) (2,274 forks)batch import
:bug: BugGood First Issue✨ Parcel 2

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

Contributor guide

Module scripts loaded with low priority when compiled · parcel-bundler/parcel#6981 | Good First Issue