EventSourcePolyfill 与原生 EventSource(性能方面)

Nag*_*ngh 5 javascript performance server-sent-events eventsource

我看到一个库允许使用HeaderEventSource 自定义标头。

事件源Polyfill

但是,当我看到网络选项卡时,Type显示的fetch不是 ,eventsource 而如果我使用本机,EventSource它会生成类型为eventsource

fetch和之间的性能有区别吗eventsource

使用 Polyfill

const eventSourceInitDict = {headers: {
        'ClientId': '123123123',
        'ClientSecret': 'lllasjdlkasjdlkasdlka'
    }};
const objEventSource1 = new EventSourcePolyfill('https://*****.herokuapp.com/emit-custom-pe?userId=' + '{!$User.Id}', eventSourceInitDict);
objEventSource1.addEventListener('message', function (objEventSourceData) {
    debugger;
});
Run Code Online (Sandbox Code Playgroud)

使用本机事件源

const objEventSource1 = new EventSource('https://****.herokuapp.com/emit-custom-pe?userId=' + '{!$User.Id}');
objEventSource1.addEventListener('message', function (objEventSourceData) {
    debugger;
});
Run Code Online (Sandbox Code Playgroud)