Thursday, 13 April 2017

Cache control with webpack and node express

My workflow is as follows:

1) I build my front-end usingwebpack with all the cool [chunkhash] to make sure my generated files have different names when there are changes and therefore busting the cache and finish with something like:

app.asdf4354234asdfchunkhashname.js
app.asdf4354234asdfchunkhashname.css
index.html

Awesome!

2) I then have a node express server to serve the above pages and an API, short version:

var express = require('express');
app.use(express.static(path.join(__dirname, '../client'))); // Where the wekback files are located after the build
...app.listen(...

So great, my JS and CSS have unique names for each versions, but the problem is that index.html gets cached and so the browser doesn't notice the new JS/CSS files. I don't think changing the name of index.html and having node filter the requests to redirect to newIndex.html is a great solution.

Question: Anything wrong in my workflow? How do I not cache index.html or let the browser know there is a new version of my files?



via denislexic

No comments:

Post a Comment