You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HTTP/2 has a great feature called push promises. It allows you to push files from server to client pro-actively because you know the client will need it. To do this responsibly, you can send along headers that can inform the client about the ETag for example, so the client can abort the file download if it's already in cache. This is all great, but very hard to deal with Express, because I would want to use all the configured Express logic in the push() API that (in my case) node-spdy expose.
In other words, I would love to combine res.sendFile() with res.push() (that node-spdy exposes). This is currently pretty much impossible as far as I can see. If Express could give more access to the internals of how a file would be delivered without actually delivering it (say, provide me with headers and a file stream I could pipe to res.push) that would be a major help. Alternative solutions of course welcome :)
Example spdy-server with Express:
constfs=require('fs');constconfig=require('config');constspdy=require('spdy');constexpress=require('express');constapp=express();constoptions={key: fs.readFileSync(config.get('server.ssl.key')),cert: fs.readFileSync(config.get('server.ssl.cert'))};consthttpServer=spdy.createServer(options,app);httpServer.listen(8080);// a route with a push promise stream:app.get('/index.html',function(req,res){// index.html is guaranteed to need styles.css// if *only* my code could look like this:res.push('/styles.css').sendFile('./www/styles.css'));res.sendFile('./www/index.html');});
Unfortunately:
Express' sendFile function really sends the file directly on the response stream. I wish I could send it on the push stream.
node-spdy doesn't make this easier because of how its push method works (see push docs, cc @indutny).
The glue has to happen somewhere, and I'm not sure where or how. But without any changes to express and/or spdy, it seems impossible to do today.
The text was updated successfully, but these errors were encountered:
i have https://github.com/jshttp/spdy-push, but it isn't updated for spdy@2, which supports http2. making it easy to push files is a matter of setting more headers. still wondering if it would be included in node, though...
node-spdy supports push() out of the box, and it seems easy enough to use. The problem is that express does a lot of logic for me to construct good responses to requests. I don't want to have to replicate though (nor have a different middleware solve it in its own way). I want to use express' internal logic, and simple API to deliver content through push. Ideally, doing a push is a one-liner, just like how most operations in Express are one-liners.
HTTP/2 has a great feature called push promises. It allows you to push files from server to client pro-actively because you know the client will need it. To do this responsibly, you can send along headers that can inform the client about the ETag for example, so the client can abort the file download if it's already in cache. This is all great, but very hard to deal with Express, because I would want to use all the configured Express logic in the
push()
API that (in my case) node-spdy expose.In other words, I would love to combine
res.sendFile()
withres.push()
(that node-spdy exposes). This is currently pretty much impossible as far as I can see. If Express could give more access to the internals of how a file would be delivered without actually delivering it (say, provide me with headers and a file stream I could pipe to res.push) that would be a major help. Alternative solutions of course welcome :)Example spdy-server with Express:
Unfortunately:
push
method works (see push docs, cc @indutny).The glue has to happen somewhere, and I'm not sure where or how. But without any changes to express and/or spdy, it seems impossible to do today.
The text was updated successfully, but these errors were encountered: