Does EventSource consume resource of browser?

37 Views Asked by At

I coded some simple SSE over HTTP/2. It worked fine as my expectation. It carried some data from the server to the client periodically.

But when I saw the dev-console of the browser, I found some scary thing,

Picture of Resource is increasing

As time goes, the amount of resources is increasing. (I think it's due to data stream of SSE).

Question:

  • Is it normal?
  • How to clear consumed SSE streams? needless?

Here is a code;

// Client
#listenSSE () {
  this.#sse = new EventSource('/_SSE/' + this.clientUID)
  this.#sse.onmessage = (event) => {
    const parsed = JSON.parse(event.data)
    console.log(parsed) // doing some job with SSE event.
  }
  this.#sse.onerror = (error) => {
    console.error('SSE error', error)
    this.#sse.close()
    this.#sse = null
  }
}

0

There are 0 best solutions below