通信方法
Web でのすべての通信方法を列挙する。
それぞれ用途、特徴があり、単純に交換できるものではない。
ActiveX などのプラグインについては無視。
ブラウザ間通信
HTML Form
https://developer.mozilla.org/ja/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript
img, script, iframe などの要素の挿入による強制 Fetch(src, href 属性などで GETパラメータを渡せば送信もできる)
JSONP https://ja.wikipedia.org/wiki/JSONP
meta refresh (iframe などで定期的に読み出すなど)
CSS などの url スキーム
XMLHttpRequest https://developer.mozilla.org/ja/docs/Web/API/XMLHttpRequest
Blob + url
https://ja.javascript.info/blob
Comet https://ja.wikipedia.org/wiki/Comet
本来は同期式の HTTP の応答を遅延させることでサーバーからの非同期の push 通信を実現したプロトコル
公式なプロトコルではなく、明確な仕様も存在しない。歴史的事情であるプロトコル。
Long Polling とも呼ばれる。
WebSocket https://developer.mozilla.org/ja/docs/Web/API/WebSockets_API
サーバーとクライアントとの双方向通信
データ形式は自由
WebRTC https://developer.mozilla.org/ja/docs/Web/API/WebRTC_API
サーバーとクライアントとの双方向通信
主にストリーミングデータを扱う
ORTC https://ortc.org/
Network Service Discovery (NSD) https://www.w3.org/TR/discovery-api/
Presentation API https://developer.mozilla.org/en-US/docs/Web/API/Presentation_API
Beacon API https://developer.mozilla.org/ja/docs/Web/API/Navigator/sendBeacon
Fetch API https://developer.mozilla.org/ja/docs/Web/API/Fetch_API
HTTP/HTTPSでデータを取得する。
Streams API https://developer.mozilla.org/ja/docs/Web/API/Streams_API
Push API https://developer.mozilla.org/ja/docs/Web/API/Push_API
Notification API https://developer.mozilla.org/ja/docs/Web/API/Notifications_API
Media Source Extensions https://developer.mozilla.org/ja/docs/Web/API/Media_Source_Extensions_API
Channel Messaging API (内部通信)
https://developer.mozilla.org/ja/docs/Web/API/Channel_Messaging_API/Using_channel_messaging
window.postMessage(obj) と message イベント (window.onmessage, window.addEventListener("message", fn) で親ウィンドウと子ウィンドウ(別ドメイン可)の間でメッセージを伝達することができる。
iframe から親を見るには document .referrer
子ウィンドウから親を見るには window.opener
Server-Sent Events https://developer.mozilla.org/ja/docs/Web/API/Server-sent_events/Using_server-sent_events
サーバーからクライアントへの一方通行
任意のタイミングで任意サイズのパケットを送信可能
データ形式はテキストのみ(MIME タイプ text/event-stream のみ)
類似する通信は WebSocket
関連
CORS
除外
File API
File API はローカルファイルを取り扱うため、リモートファイル(URL)ではアクセスできない。
参考
最新Web 通信系API総まくり!WebRTC, Streams, Push api etc. https://www.slideshare.net/KensakuKOMATSU/web-apiwebrtc-streams-push-api-etc
The WebM Project https://www.webmproject.org/