tc39 / proposal-dynamic-import

import() proposal for JavaScript

Home Page:https://tc39.github.io/proposal-dynamic-import/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authentication and dynamic imports

aapoalas opened this issue · comments

Hello

Chrome has already rolled out dynamic ES6 imports. I have been wanting to try it out with a system where part of the UI data is fetched from a remote server / other localhosted server. Problem is that this data is, naturally, hidden behind an authentication layer and, as far as I understand, there is currently no way to send credentials with the dynamic import.

I readily admit myself to be woefully ignorant of the deeper implications of credentials inclusion in dynamic imports, but it does nevertheless seem to me like this feature will be of utmost importance to many use cases. Is there any road map with regards to authentication with dynamic imports?

You can use them within a <script> whose crossorigin="" attribute is set appropriately to give credentials. This applies to all imports, not just dynamic ones.

Ah, thank you for enlightening me! Now I feel way stupid :)

@domenic For my understanding, does that mean I can do:

<script type="module" src="foo.js" crossorigin=""></script>
// foo.js

import './bar.js';
import('./baz.js');

Then foo.js, bar.js and baz.js should all be loaded with credentials?