HTTP push — один из вариантов распространения контента в Интернете, когда информация поступает от сервера к клиенту.
Альтернативные названия:
Как забороть?
$.getJSON('m.com/?callback=?', function(data) {
alert(data);
});
Нюансы:
document.createElement('script');
window.setTimeout();
document.domain = 'home.com';
$.get('http://my.home.com/', function(data) {
alert(data);
});
Нюансы:
Access-Control-Allow-Origin: http://foo.mysite.com
FF3.5+, Safari4+, Chrome3+, IE8+
var o = document.getElementsByTagName('iframe')[0];
o.contentWindow.postMessage('Hello B', 'http://documentB.com/');
Document B:
window.addEventListener('message', function(event) {
alert(event.data);
});
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
23
This is the data in the first chunk
1A
and this is the second one
0
Content-type: multipart/x-mixed-replace
onreadystatechange
function waitForMsg(){
$.ajax({
type: "GET",
url: "/messages",
cache: false,
timeout: 50000, // 50s
success: function(data){
setTimeout(waitForMsg, 1000);
}
});
}
Добавляем JSONP и получаем
var source = new EventSource('/stats');
source.onmessage = function (event) {
// process server message
};
var ws = new WebSocket("ws://localhost/echo");
ws.onopen = function() {
ws.send("Message to send");
};
ws.onmessage = function(evt) {
// Message is received
};
# Subscribe
curl -s -v 'http://localhost/sub/my_channel_1'
# Publish
curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello!'
# Delete Channel
curl -s -v -X DELETE 'http://localhost/pub?id=my_channel_1'
# All Channels Stats summarized (json format)
curl -s -v 'http://localhost/channels-stats'
var pushstream = new PushStream({
host: window.location.hostname,
port: window.location.port,
modes: "websocket|eventsource|longpolling|stream"
});
pushstream.onmessage = function(text, id, channel) {
// process message
};
pushstream.addChannel('ch1');
pushstream.connect();
— 50K connections
— 9K msg/sec
Use a spacebar or arrow keys to navigate