Node.js HTTP2推送-在res.end中放置脚本标记
读完后,我有一个问题 http2push的好处是浏览器在请求资源之前就缓存了这些资源 在本例中: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
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',…)
我对此也很感兴趣。有人问我是否正在中的文档中添加资源。