DecisionLoad JavaScript as external resource with async and defer attributes


Loading JavaScript as async & deferred has the best default performance


This ADR has been replaced by this new version.

When loading external JavaScript files in HTML, they will have the async and defer attributes.

  <script src="/path/to/file.js" async defer>

When adding JavaScript files with Drupal Libraries, this will require adding the async and defer attributes on a per-file basis:

  version: 1.0.0
        async: true
        defer: true


Adding async and defer to <script src="..."> tags will create the most performant page-loading experience:

  • The async attribute tells the browser to continue parsing HTML while the JavaScript file is downloading. Without the async attribute, the initial rendering of the page could be significantly delayed on devices with a slower connection speed.

  • The defer attribute tells the browser to avoid executing the JavaScript until the entire document has been parsed. Without the defer attribute, the initial rendering of the page could be significantly delayed on devices with older or slower processors.

By adding both the async and defer attributes on <script src="..."> tags, we minimize the impact of external JavaScript files as much as possible.


There are rare instances when JavaScript should be added into the body of the HTML document, such as removing a no-js class from the <html> element. In this case, inline blocking JavaScript is preferable to avoid cumulative layout shifts and perceived reflows of the document. For example, in the code below, the HTML document is sent to the browser with a no-js class to prevent displaying portions of the page that require JavaScript. By adding an inline style early in the document, we can prevent the browser from rendering the page once with the no-js class and then reflowing when no-js is removed.

<html class="no-js">
      .no-js #app {


Requesting & executing JavaScript in this manner should lead to more performant page loading and the most consistent script execution since scripts will not run until the entire DOM is in place. This, in turn, will create a better experience for end-users and a better score on objective performance metrics.

Additional Resources

Andy Blum, Chris DeLuca, Mateu Aguiló Bosch, Sally Young

Decided on