const http2 = require('http2'); const server = http2.createSecureServer({cert, key}, onRequest); function push (stream, filePath) { const {file, headers} = getFile(filePath); const pushHeaders = {[HTTP2_HEADER_PATH]: filePath }; stream.pushStream(pushHeaders, (pushStream) => { pushStream.respondWithFD(file, headers); }); } function onRequest (req, res) { // Push files with index.html if (reqPath === '/index.html') { push(res.stream, 'bundle1.js'); push(res.stream, 'bundle2.js'); } // Serve file res.stream.respondWithFD(file.fileDescriptor, file.headers); }
Source : HTTP/2 Server Push with Node.js
Pour HTTP/2 avec Express, on peut utiliser spdy.