Express JS - Want to cache static resources but NOT rendered HTML
<p>I'm working on a dynamic application where we don't want to cache HTML (i.e. cart contents can change from one page refresh to the next). To that end, I'm calling middleware that sets cache-control headers to avoid caching. However, said cache-control headers also apply when fetching static resources. For obvious performance reasons, this is undesired behavior. We def want to cache static resources. My question is this... Is there a way to set diff response headers for static resources vs rendered html? I tried passing the setHeaders option to the express.static middleware, but the thread hangs, presumably because we are trying to set the same response header twice. Any help is greatly appreciated!</p>

<p><strong>Edit</strong>: adding environment information -</p>

<p>I'm on Express 4 and Node 4.4</p>

<p><strong>Edit</strong>: adding example code. This is the relevant bit from app.js that aggressively avoids caching HTML in browser.</p>

<pre><code>app.use(express.static(config.static.public));

// ...Stuff

app.use(function (req, res, next) {

    // Don't cache html
    res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, '
        + 'max-stale=0, post-check=0, pre-check=0');
    res.set('Expires', 'Fri, 31 Dec 1998 12:00:00 GMT');
    next();

});
</code></pre>