Skip to content

Commit 4df44dc

Browse files
committed
refactor(@angular/build): use ETags for dev-server resource requests
When using the development server with the application build system, resource files managed by the build system will now using ETag headers to avoid resending content that has not changed since the last request. This includes such content as global stylesheet files, image/font files referenced in stylesheets, and other files managed by the bundler.
1 parent b3fe50f commit 4df44dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,21 @@ export function createAngularAssetsMiddleware(
119119
}
120120
}
121121

122+
// Avoid resending the content if it has not changed since last request
123+
const etag = `W/"${outputFile.contents.byteLength}-${outputFile.hash}"`;
124+
if (req.headers['if-none-match'] === etag) {
125+
res.statusCode = 304;
126+
res.end();
127+
128+
return;
129+
}
130+
122131
const mimeType = lookupMimeType(extension);
123132
if (mimeType) {
124133
res.setHeader('Content-Type', mimeType);
125134
}
126135
res.setHeader('Cache-Control', 'no-cache');
136+
res.setHeader('ETag', etag);
127137
res.end(data);
128138

129139
return;

0 commit comments

Comments
 (0)