Following this convo:
Your browser requests https://unpkg.com/foo:
<script type='module' src='https://unpkg.com/foo'></script>
unpkg responds with the contents of foo...
import bar from './bar.js';
alert( bar );
...but it also scans the file and sees the import
declaration, resolves it (because it already knows that /foo
resolves to /foo@1.2.3/lib/index.js
) and is thus able to server push https://unpkg.com/foo@1.2.3/lib/bar.js.
The browser receives foo.js, and parses it. Upon doing so, it sees that it needs to fetch bar.js before it can evaluate the code, so it makes a separate request to https://unpkg.com/foo@1.2.3/lib/bar.js. But because unpkg had already pushed bar.js, the file is already on its way (may even have already arrived, in fact), saving the costs of going back and forth to progressively fetch new modules.
If this worked out-of-the-box, unpkg's speed would be pretty hard to beat.