Video in progress

What is the difference between ws:// and wss://, and which one do you use in production?

ws:// is unencrypted WebSocket, wss:// is WebSocket over TLS, just like http and https. In production, only wss://: the traffic is encrypted and corporate proxies are less likely to break the connection.

📖 Answer

wss:// runs inside TLS on port 443. So tokens, chat messages and personal data are not visible on the network.

Another practical reason: if the page was opened over https://, the browser won't let it connect to ws://. You get a "mixed content" error.

// pick based on the page protocol
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
const socket = new WebSocket(`${proto}://${location.host}/ws`);

In practice TLS usually terminates at Nginx or the load balancer, and the Spring Boot app inside just speaks plain ws. That's normal; the proxy only has to pass the Upgrade headers through correctly.

For local development, using ws://localhost:8080/ws is perfectly fine.