WebSocket を通じた HTML:JavaScript は最小限のリアルタイム SPA
## Japanese Translation:
単一ページアプリケーション(SPA)において、重い JavaScript に依存するのは開発者が WebSockets に対して HTML を採用する場合には不要である。このアーキテクチャは Chris McCord が Phoenix LiveView で開拓し、レンダリングロジックをすべてバックエンドにシフトさせ、Elixir の Phoenix、Ruby の Hotwire、Python の Livewire、C#'s Blazor、PHP の Livewire 3 および agnostic ツールの htmx を含むフレームワークにおいて、ロジックとプレゼンテーションを一つの言語で処理することを可能にしている。複雑なフロントエンドフレームワークまたは精巧な API コントラクトの代わりに、システムは HTML 内でリアルタイムサーバーサイドの状態管理を直接行うことで開発を簡素化する。
主な利点は固有のセキュリティとパフォーマンスであり、クロスサイトスクリプティング(XSS)攻撃に対する組み込みの保護を提供しつつ、恒常的なポーリングや JSON データの前処理なしに瞬時の双方向更新を維持する。クライアントの役割は WebSocket チャンネルへの接続および受信された HTML の DOM への挿入に限られる。このアプローチにより、コンテンツは検索エンジン最適化(SEO)に対して直ちにインデックス可能となるが、クロワラーはその後続する WebSocket 更新を見ることができないため、重要なコンテンツは初期レスポンスに存在する必要がある。サーバー送付イベント(SSE)は通知や AI ストリームなどの一方通行通信のより安価な代替手段を提供するが、マルチプレイヤーゲームやライブダッシュボードのような複雑なアプリケーションでネイティブなクライアント対サーバー通信が必要となる場合、フル WebSockets のインタラクティビティに匹敵することはできない。究極的には、企業はフロントエンドの複雑性の大幅な削減とスケーラブルなリアルタイムソリューションのために、より高いサーバーリソース(共有状態機構としての Redis などをしばしば必要とする)をトレードしている。
## Text to translate:
The text argues that Single-page Applications relying on heavy JavaScript are unnecessary when developers adopt HTML over WebSockets. This architecture, pioneered by Chris McCord with Phoenix LiveView, shifts all rendering logic to the back-end, allowing a single language to handle both logic and presentation across frameworks like Elixir's Phoenix, Ruby's Hotwire, Python's Livewire, C#'s Blazor, PHP's Livewire 3, and agnostic tools like htmx. Instead of complex frontend frameworks or intricate API contracts, the system simplifies development by enabling real-time server-side state management directly in HTML.
The primary benefit is intrinsic security and performance; it offers built-in protection against Cross-Site Scripting (XSS) attacks while maintaining instant bidirectional updates without needing constant polling or JSON data preprocessing. The client's role shrinks to merely connecting a WebSocket channel and injecting received HTML into the DOM. This approach ensures content is immediately indexable for Search Engine Optimization, although crawlers do not see subsequent WebSocket updates, meaning critical content must be present in the initial response. While Server-Sent Events (SSE) offer a cheaper alternative for one-way communication like notifications or AI streams, they cannot match the interactivity of full WebSockets for complex applications like multiplayer games or live dashboards where native client-to-server communication is needed. Ultimately, companies trade higher server resources (often requiring shared state mechanisms like Redis) for significantly reduced frontend complexity and scalable real-time solutions.