Internet Explorer 中的 Blazor

Blazor in Internet Explorer

我正在尝试 运行 Internet Explorer 中的 blazor 应用程序。在 blazor 页面上有一条通知,指出对于不支持 webassembly 的浏览器,可以回退到 asm.js。当我在 IE 中加载页面时(链接了 blazor.pollyfil.js 脚本),我只收到错误消息“浏览器不支持 WebAssembly”。

我能够 运行 服务器模式下的应用程序(使用 SignalR 连接到呈现服务器),但它是适用于所有浏览器的解决方案,并且失去了 Web 程序集的优势。

有没有办法仅在 Internet Explorer 中正确回退到 asm.js 模式?

WebAssembly 未包含在 Internet Explorer features. You can learn about browser compatibility at mozilla.org 中,不,IE 不支持 WebAssembly。

记住 IE 是 discontinued, but still maintained:

Will Internet Explorer 11 continue to receive updates?

The latest features and platform updates will only be available in Microsoft Edge. We will continue to deliver security updates to Internet Explorer 11 through its supported lifespan. To ensure consistent behavior across Windows versions, we will evaluate Internet Explorer 11 bugs for servicing on a case by case basis.

从 WebAssembly 更改为组件模式只是几行更改代码,但同时部署这两种模式以保持对 IE 的兼容性似乎很奇怪。请记住 Blazor 是实验性的,我想对于真正的部署,您应该等待一段时间...是时候从 IE 更新到其他浏览器了。

Is there really way how to correctly fall back to asm.js mode in (only) Internet Explorer?

我猜是与 相同的问题,只需调整 Blazor 的答案:

const isClientSideWebAssemblySupported = (() => {
    try {
        if (typeof WebAssembly === "object"
            && typeof WebAssembly.instantiate === "function") {
            const module = new WebAssembly.Module(
                               Uint8Array.of(0x0, 0x61, 0x73, 0x6d,
                                             0x01, 0x00, 0x00, 0x00));
            if (module instanceof WebAssembly.Module)
                return new WebAssembly.Instance(module) 
                           instanceof WebAssembly.Instance;
        }
    } catch (e) {
    }
    return false;
})();

var script = document.createElement('script');
script.src = (isClientSideWebAssemblySupported)?
             "_framework/blazor.server.js":
             "_framework/blazor.webassembly.js";

记得在您的项目中包含这两个 js

看来其他用户也遇到了这个问题。

该用户发现问题出在 polyfill(当然还有 Internet Explorer 11),并且它出现在 babel / core-js 和其他兼容的 polyfill 中。

IE11 似乎在对 Symbol 进行深度 setter 递归时遇到了一些困难,并且出现 Stack memory exceeded 错误。

他还尝试修复 polyfill。您可以尝试用它进行测试,看看它是否有助于解决您的问题。

参考:

asm.js fallback not working on IE11

Polyfills for Blazor (for Internet Explorer 11 support and some other browsers)

在此提交中有意从 Blazor 中删除了对 asm.js 的支持:https://github.com/aspnet/Blazor/commit/4006cd543900fcc1cf76cd75a1b24007e60c8a67。如果我理解正确,从 stock blazor 获得 asm.js 支持将需要单声道项目开始在其二进制分发中包含一个 asm.js 构建,并且 Blazor 项目将其添加回其 build/deploy 工装.

我还没有尝试过,但也许可以自己为 asm.js 构建单声道并将其作为您自己的部署过程的一部分注入到您构建的 Blazor 应用程序中。

如果我理解正确,Blazor 仍然使用单声道的解释模式运行,因此用 asm.js 补充单声道的 wasm 构建可能仍然足够。如果以后Blazor切换到实际直接编译程序集到wasm,事情会变得更复杂。

备选方案

Blazor 支持 server-side hosting mode. You already mentioned this in your question, but I am discussing this here in case others skipped over that. In server hosting mode, the client only needs to be able to run “traditional” JavaScript (though it may need polyfills). This can be made to work in IE11 and other clients lacking wasm support. Of course, this takes more resources on the server, prevents the client from supporting offline scenarios, and is basically like a glorified telnet session. But this may be sufficient for LOB applications