Immutable caching of static assets with Express.js and Service Worker
This recipe revisions all asset files in a dist/assets/
directory using gulp-rev
.
The adds a unique content based hash to each asset file.
The pattern of that hash (/.*-[0-9a-f]{10}\..*/
) is then used to handle these files in Express.js and the Service Worker.
Express.js sets the Cache-Control
header to immutable
.
The Service Worker serves these files directly from cache without ever attempting the server again.