QA
Intermediate LevelHTML & Semantic Web

How does the EventSource API handle real-time Server-Sent Events (SSE) in HTML?

❓ Interview Prompt: Explain EventSource initialization, text/event-stream format, automatic reconnection, and handling message events.

The 'EventSource' API provides client-side handling for Server-Sent Events (SSE), streaming real-time text updates over persistent HTTP connections.

Advantages over WebSockets:

•
Built on standard HTTP.
•
Automatic reconnection handling.
•
Built-in event IDs for resuming interrupted streams.

Code Implementation Example

html
<script>
  const eventSource = new EventSource('/api/live-updates');
  
  eventSource.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log('Received SSE update:', data);
  };
</script>
💡Connecting client EventSource listener to Server-Sent Events endpoint.
🎯 Interview Key Takeaway

Use EventSource for unidirectional real-time server updates with built-in automatic reconnection handling.

#SSE#EventSource#Real-Time#Intermediate
Back to all HTML & Semantic Web Questions→

More HTML & Semantic Web Interview Questions

Beginner LevelHTML & Semantic Web

What is Semantic HTML and why is it essential for modern web applications?

Beginner LevelHTML & Semantic Web

What is <!DOCTYPE html> and what happens if it is omitted?

Beginner LevelHTML & Semantic Web

What is the difference between inline and block-level HTML elements?