如何让 <script type="module"> 使用给定的授权 header?

How do I get <script type="module"> to use the given Authorization header?

加载具有多个 <script><script type="module"> 声明的网站时,Authorization: header 适用于脚本,但不适用于模块。

<script src="lib/a-lib.js"></script> 有效

<script type="module" src="app/a-module.js"></script> 遇到了 401。

URL 中的

Username/Password 也适用:<script type="module" src="https://user:password@domain/app/a-module.js"></script>。但由于 username:password 未转换为 Header,因此这不是解决方案。

我刚刚进行了快速谷歌搜索,因为它很有趣并发现了这个:

You can add credentials to a same-origin module by including the crossorigin attribute (which seems a bit weird to me, and I've questioned this in the spec). If you want to send credentials to other origins too, use crossorigin="use-credentials". Note that the other origin will have to respond with the Access-Control-Allow-Credentials: true header.

jake's site

希望对您有所帮助 ;)