title: Express response interception. Use body to modify the outgoing headers
body: <p>I would like to try and improve site render times by making use of <a href="https://www.keycdn.com/blog/http-preload-vs-http2-push" rel="nofollow noreferrer">preload/push headers</a>. </p>
  
  <p>We have various assets which are required up front that I would like to preload, and various assets which are marked up in data attributes etc which will be required later via JS but not for initial paint. It would be good to get these flowing to the client early.</p>
  
  <p>Our application is a bit of a hybrid, it uses <a href="https://github.com/chimurai/http-proxy-middleware" rel="nofollow noreferrer">http-proxy-middleware</a> connected to various different applications, plus directly renders pages it self. I would like the middleware to be agnostic and work regardless of how to page is produced.</p>
  
  <p>I've seen <a href="https://www.npmjs.com/package/express-mung" rel="nofollow noreferrer">express-mung</a> but this doesn't hold back the header so executes too late, and works with chunked buffers anyway not the entire response. Next up was <a href="https://github.com/axiomzen/express-interceptor" rel="nofollow noreferrer">express-interceptor</a>, that works perfectly for pages rendered directly in express but causes request failures for pages run through the proxy. My next best idea is pulling apart the <a href="https://www.npmjs.com/package/compression" rel="nofollow noreferrer">compression</a> module to figure out how it works.</p>
  
  <p>Does anyone have a better suggestion, or even better know of a working module for this kind of thing?</p>
  
  <p>Thanks.</p>