[Typo]: definitions of async/defer in the script tag documentation are incorrect
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
Summary
Unless React has its own creative interpretation of the meanings of async and defer that are different from the DOM specification (per MDN), the descriptions for async and defer are confusing and misleading and may lead to runtime errors.
Page
https://react.dev/reference/react-dom/components/script
Details
The description for async confounds it with defer, but in fact async essentially cancels any kind of defer: the script will not block further parsing, but it will be executed as soon as it is available, there is no "deferring". This lets the browser execute it at its convenience, there is no longer any guarantee about when it runs other than "eventually": this can even be mid-parse!
defer, on the other hand, also doesn't block parsing by enqueueing the script to run after the page finishes parsing; but they are guaranteed to run before the DOMContentLoaded event. This is, actually, what is recommended for most scripts, enough that it is the default for script[type="module"]. It is canceled by async, as it removes the guarantee that the script will run only after parse is done. It only has an effect on src scripts, though, not inline.
It is, however, true that async is the best for performance, as there is no longer any execution time guarantees. It is also dangerous, as the DOM might not be available when the script runs: only (non-async) defer scripts have that guarantee.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
開啟 https://react.dev/reference/react-dom/components/script 上的 React DOM 指令碼文件,並將 async 和 defer 的說明與連結的 MDN DOM 規範進行比較。更新措辭,以準確區分它們的執行時機、剖析行為以及對外部指令碼的適用性,然後確認頁面是否清楚傳達了執行階段的影響。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100