Decisions about javascript
Architectural decision records tagged with javascript
-
acceptedLoad JavaScript libraries conditionally
Loading all JavaScript globally increases initial page weight and slows down pages that don't need it.
-
acceptedUse data-drupal-selector to target form elements in JavaScript
Classes and IDs are unstable JavaScript targets in Drupal, while data-drupal-selector is a stable hook provided by the Form API.
-
acceptedRespect prefers-reduced-motion for all animations and transitions
Users with vestibular disorders rely on the prefers-reduced-motion media query to disable or reduce motion that can cause discomfort.
-
acceptedSelf-host Third-Party Static Assets
Third-party hosted assets (e.g. web fonts, icon libraries) can lead to performance, privacy, and reliability issues. These include GDPR violations, extra DNS lookups, and outages outside the organization control.
-
acceptedAvoid using jQuery
jQuery is an unnecessary dependency for modern browsers.
-
acceptedLoad JavaScript as external resource with defer attribute
Loading JavaScript as deferred has the best default performance
-
deprecatedLoad JavaScript as external resource with async and defer attributes
Loading JavaScript as async & deferred has the best default performance
-
acceptedUse JavaScript strict mode
Opt in to settings that raise errors for problematic code.
-
acceptedUse TypeScript for pure JavaScript development
Strictly typed languages like TypeScript avoid unexpected behavior, prevent bugs, and improve code maintainability.