Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js HTTP2推送-在res.end中放置脚本标记_Node.js_Spdy_Http2 - Fatal编程技术网

Node.js HTTP2推送-在res.end中放置脚本标记

Node.js HTTP2推送-在res.end中放置脚本标记,node.js,spdy,http2,Node.js,Spdy,Http2,读完后,我有一个问题 http2push的好处是浏览器在请求资源之前就缓存了这些资源 在本例中: spdy.createServer(options, function(req, res) { // push JavaScript asset (/main.js) to the client res.push('/main.js', {'content-type': 'application/javascript'}, function(err, stream) { stream

读完后,我有一个问题

http2push的好处是浏览器在请求资源之前就缓存了这些资源

在本例中:

spdy.createServer(options, function(req, res) {
  // push JavaScript asset (/main.js) to the client
  res.push('/main.js', {'content-type': 'application/javascript'}, function(err, stream) {
    stream.end('alert("hello from push stream!")');
  });

  // write main response body and terminate stream
  res.end('Hello World! <script src="/main.js"></script>');
}).listen(443);
spdy.createServer(选项、功能(请求、恢复){
//将JavaScript资产(/main.js)推送到客户端
res.push('/main.js',{'content-type':'application/javascript'},函数(err,stream){
end('警报(“推送流中的你好!”);
});
//写入主响应体并终止流
res.end(“你好,世界!”);
}).听(443);
究竟是什么导致浏览器在
res.end('Hello World!')
中执行的操作

如果index.html里面有
,为什么要把它放在
res.end('Hello World!')

res.end('Hello World!')正在发送一个非常小的网页。(它缺少
等…
,因为它是一个简单的示例。)它看起来像这样:

Hello World!
<script src="/main.js"></script>
你好,世界!
网页显示“Hello World!”,但您不会看到呈现的
标记。浏览器解析“网页”,处理指向
main.js
的链接,并发现它已收到该文件(从
.push
)。最后,执行该脚本并打开一个
警报()


main.js
甚至在“网页”内容交付之前就被抢先发送,这就是
res.push('/main.js',…)

我对此也很感兴趣。有人问我是否正在中的文档中添加资源。