Why is it faster to put an empty src attribute than not putting any?

Viewed 304

I'm working in local with Bootstrap, jQuery and HTML. When you click in a button you get a data-url which gets put into an iframe video. If you put an empty src="", it is so much faster than not putting anything. Why is that? Apparently it looks like it doesn't matter.

Example:

<script>
var youtube = "https://www.youtube.com/embed/"
    $("button[data-url]").click(function() {
      var code = $(this).data("url")
      var video = youtube + code
      $("iframe").attr("src", video)
    })
</script>

<button type="button" data-url="WhateverCode1">Video 1</button>
<button type="button" data-url="WhateverCode2">Video 2</button>

<!--With src="" is so much faster -->
<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item" src=""></iframe>
</div>

<!-- Than no src -->
<div class="embed-responsive embed-responsive-16by9">
  <iframe class="embed-responsive-item"></iframe>
</div>
1 Answers

It's not matter of the setting src, when you click button it's set the src value or create the src attribute with it's value to it's DOM at the same time.

HTML render/populate all it's DOM in procedural way(top to bottom), So the first one load first, then the second one & so on.

Related