doriver 2025. 2. 12. 01:48

1. 

chatList.html에 <script src="/js/chatting/chatList.js"></script>가 있고

// chatList.js
let loginId;
let eventSource = new EventSource("/sse/chatList");

sse는 스프링부트와 통신하고있는데

 

브라우저가 chatList.html를 렌더링하다가, chatRoom.html를 렌더링하면

변수 loginId랑 스프링부트와의 sse통신은 어떻게 될까?

 

>>>

chatList.js는 chatList.html에서만 로드되는 상황.

페이지가 이동하면(chatRoom.html로 전환되면),
chatList.html과 함께 실행 중이던 chatList.js가 종료됨.

chatList.js의 모든 변수(loginId 포함)는 삭제됨
eventSource 객체도 더 이상 유지되지 않으며 자동으로 SSE 연결이 종료됨.

 

 

2.