Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default import('./async').then(() => document.head.children);
25 changes: 25 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,31 @@ describe('javascript', function () {
assert.deepEqual(res, {default: 42});
});

it('dynamic imports loaded as high-priority scripts when not all engines support esmodules natively', async function () {
let b = await bundle(
path.join(__dirname, '/integration/dynamic-imports-high-prio/index.js'),
{
defaultTargetOptions: {
engines: {
browsers: 'IE 11',
},
},
},
);

let output = await run(b);
let headChildren = await output.default;

assert(headChildren[1].tag === 'link');
assert(headChildren[1].rel === 'preload');
assert(headChildren[1].as === 'script');

assert(headChildren[1].href === headChildren[2].src);

assert(headChildren[2].tag === 'script');
assert(headChildren[2].src.match(/async\..*\.js/));
Comment thread
highvoltag3 marked this conversation as resolved.
Outdated
});

it('should support bundling workers with dynamic import in both page and worker', async function () {
let b = await bundle(
path.join(__dirname, '/integration/worker-dynamic/index-async.js'),
Expand Down
7 changes: 7 additions & 0 deletions packages/runtimes/js/src/helpers/browser/js-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module.exports = cacheLoader(function loadJSBundle(bundle) {
return;
}

var preloadLink = document.createElement('link');
preloadLink.href = bundle;
preloadLink.rel = 'preload';
preloadLink.as = 'script';
document.head.appendChild(preloadLink);

var script = document.createElement('script');
script.async = true;
script.type = 'text/javascript';
Expand All @@ -32,6 +38,7 @@ module.exports = cacheLoader(function loadJSBundle(bundle) {
resolve();
};

document.getElementsByTagName('head')[0].appendChild(preloadLink);
document.getElementsByTagName('head')[0].appendChild(script);
});
});