HTTP Response before Request

后端 未结 7 1870
梦毁少年i
梦毁少年i 2020-12-23 17:16

My question might sound stupid, but I just wanted to be sure:

  • Is it possible to send an HTTP response before having the request for that resource?
7条回答
  •  感动是毒
    2020-12-23 17:46

    A recent post by Jacques Mattheij, referencing your very question, claims that although HTTP was designed as a synchronous protocol, the implementation was not. In practise the browser (he doesn't specify which exactly) accepts answers to requests have not been sent yet.

    On the other hand, if you are looking to something less hacky, you could have a look at :

    • push techniques that allows the server to send content to the browser. The modern implementation that replace long-polling/Comet "hacks" are the websockets. You may want to have a look at socket.io also.
    • Alternatively you may want to have a look at client-side routing. Some implementations combine this with caching techniques (like in derby.js I believe).

提交回复
热议问题