diff --git a/core/includes/common.inc b/core/includes/common.inc
index 14154af7b4f0c1fd8614b56e1561c769ca8a9748..fea16e1a1924433d79ec0d4768607b8c049b5fad 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4321,9 +4321,6 @@ function drupal_pre_render_scripts($elements) {
       foreach ($group['items'] as $item) {
         // Element properties that do not depend on item type.
         $element = $element_defaults;
-        if (!empty($item['defer'])) {
-          $element['#attributes']['defer'] = 'defer';
-        }
         $element['#browsers'] = $item['browsers'];
 
         // Element properties that depend on item type.
@@ -4351,6 +4348,11 @@ function drupal_pre_render_scripts($elements) {
             break;
         }
 
+        // The defer attribute must not be specified if src is not defined.
+        if (!empty($item['defer']) && isset($element['#attributes']['src'])) {
+          $element['#attributes']['defer'] = 'defer';
+        }
+
         $elements[] = $element;
       }
     }