Skip to main content

Optimization

Script Loading​

Aspectinline scriptsyncasyncdeferexternal + type="module"
Visualization
Present in Tag

<script>...</script>

<script src="..."></script>

<script async src="..."></script>

<script defer src="..."></script>

<script type="module" src="..."></script>

Loading Behaviorscript is executed immediately when encounteredscript is fetched immediately as the browser encounters the tagscript is fetched in parallel with HTML parsingscript is fetched in parallel with HTML parsingfetched in parallel
Execution Timingimmediate executionscript is executed immediately after it's downloaded, before continuing parsing the HTML documentscript is executed as soon as it's downloaded, even if the HTML parsing is not finishedscript is executed in order after HTML parsing is fully complete, just before DOMContentLoadeddeferred by default, executed after parsing
Execution Orderbased on document locationpreserved, as per DOM ordernot preserved - random orderpreservedpreserved (per top-level await and import graph)
Blocking Behaviorblocks HTML parsingblocks HTML parsingmay block parsing at executiondoes not block parsingdeferred behavior
Notesavoid for large code blocks; inline code can't use async or deferdefault behavior; loading blocks renderingnon-deterministic execution order; may lead to race conditionsmost preferred for non-blocking DOM-safe executionalways deferred by spec; uses strict mode automatically
Use Casescritical inline JS; not affected by async / deferscripts that must run immediately, and manipulate DOM elements above themanalytics, tracking, or other scripts that don't depend on DOM or other scriptsscripts that depend on DOM elements, and must maintain execution ordermodern ES Modules and top-level imports

Optimization Strategies​

StrategyDescription
Minimize HTTP Requests

Fewer files mean faster load times due to reduced browser requests

Reduce File SizesSmaller assets (images, code, videos) download more quickly
Optimize Critical Rendering Path (CRP)Improve how fast key content appears and becomes usable
Leverage CachingStore files in-browser or via CDN to speed up repeat visits
Prioritize User Experience

Make the site feel fast and responsive, even if not fully loaded

Reduce Server Response Time (SSR)Faster backend response improves overall frontend speed