Cache busting with a content hash

Javascript

Names the built file after its contents so a deploy invalidates the cache without a version bump.

import { createHash } from 'node:crypto';
import { readFileSync, renameSync } from 'node:fs';

const css = readFileSync('dist/app.css');
const hash = createHash('sha256').update(css).digest('hex').slice(0, 8);
renameSync('dist/app.css', `dist/app.${hash}.css`);
console.log(`app.${hash}.css`);

More in Build & CI

Random picks