I'm trying to understand, why HTML5 Import doesn't work with dynamically created link
element.
First example. It's work fine.
main_page.html:
<head>
<link rel="import" href="import.html">
</head>
<body>
<script>
var imported = document.querySelector('link[rel="import"]').import;
var el = imported.querySelector('#foo');
document.body.appendChild(el);
</script>
</body>
import.html:
<div id="foo">foo</div>
Second example. For some reason, it doesn't work.
main_page.html:
<body>
<script>
var link = document.createElement('link');
link.rel = 'import';
link.href = 'import.html';
document.head.appendChild(link);
var imported = document.querySelector('link[rel="import"]').import;
var el = imported.querySelector('#foo');
document.body.appendChild(el);
</script>
</body>
import.html:
<div id="foo">foo</div>
Why it occurs and how it may be fixed?