Skip to content

Commit

Permalink
perf(tools): dev server uses mtime for etag
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jul 15, 2024
1 parent a486b90 commit 25bee8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-phones-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@patternfly/pfe-tools": patch
---

**Dev Server**: use last modified time for the dev server cache
8 changes: 5 additions & 3 deletions tools/pfe-tools/dev-server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 25bee8c

Please sign in to comment.