Wener Notes

Server-Sent Events

约 1 分钟阅读

**\n\n 分隔 **

text
data: message\n\n

可以多行

text
data: first line\n
data: second line\n\n

支持额外字段

text
id: 12345\n
data: GOOG\n
data: 556\n\n

  • id
    • Last-Event-ID
    • e.lastEventId
  • data
  • retry: 3000
    • 3s
  • event
    • 事件名字
JavaScript
var source = new EventSource('/events');
source.onmessage = function (e) {
  console.log(e.data);
};

关联信息

反向链接、本文链接的其他页面和外部资料。

References

GitHub1 条
Hacker News1 条
其他外链2 条
最近更新commit ac6d47fEdit

On this page