diff --git a/.changeset/tender-phones-visit.md b/.changeset/tender-phones-visit.md new file mode 100644 index 0000000000..1978c942ab --- /dev/null +++ b/.changeset/tender-phones-visit.md @@ -0,0 +1,5 @@ +--- +"@patternfly/pfe-tools": patch +--- + +**Dev Server**: use last modified time for the dev server cache diff --git a/tools/pfe-tools/dev-server/config.ts b/tools/pfe-tools/dev-server/config.ts index 85733bb465..5c2cf90f7c 100644 --- a/tools/pfe-tools/dev-server/config.ts +++ b/tools/pfe-tools/dev-server/config.ts @@ -18,6 +18,7 @@ import { } from './plugins/import-map-generator.js'; import { pfeDevServerPlugin } from './plugins/pfe-dev-server.js'; +import { join } from 'node:path'; const replace = fromRollup(rollupReplace); @@ -75,11 +76,12 @@ function cors(ctx: Context, next: Next) { async function cacheBusterMiddleware(ctx: Context, next: Next) { await next(); if (ctx.path.match(/(elements|pfe-core)\/.*\.js$/)) { - const lm = new Date().toString(); - const etag = Date.now().toString(); + const stats = await stat(join(process.cwd(), ctx.path)); + const mtime = stats.mtime.getTime(); + const etag = `modified-${mtime}`; ctx.response.set('Cache-Control', 'no-store, no-cache, must-revalidate'); ctx.response.set('Pragma', 'no-cache'); - ctx.response.set('Last-Modified', lm); + ctx.response.set('Last-Modified', mtime.toString()); ctx.response.etag = etag; } }