Disable HTML caching in static runtime responses
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
524ba15e62
commit
fc16b8ac58
2 files changed
+13
No files matched your search
@@ -168,6 +168,13 @@ async function main() {
|
||||
if (page.headers.get("x-content-type-options") !== "nosniff") {
|
||||
throw new Error("Smoke test failed: expected x-content-type-options=nosniff.");
|
||||
}
|
||||
if ((page.headers.get("cache-control") ?? "").toLowerCase() !== "no-store") {
|
||||
throw new Error(
|
||||
`Smoke test failed: expected cache-control=no-store, got ${String(
|
||||
page.headers.get("cache-control"),
|
||||
)}.`,
|
||||
);
|
||||
}
|
||||
const missingAssetUrl = new URL("/assets/missing-bundle.js", parsedAppUrl);
|
||||
const missingAsset = await fetch(missingAssetUrl);
|
||||
if (missingAsset.status !== 404) {
|
||||
|
||||
@@ -614,6 +614,9 @@ function startStaticWebServer(distRoot: string, port: number) {
|
||||
response.setHeader("Content-Type", contentTypeFor(targetPath));
|
||||
response.setHeader("Content-Length", String(stats.size));
|
||||
response.setHeader("X-Content-Type-Options", "nosniff");
|
||||
if (targetPath.endsWith(".html")) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
}
|
||||
response.end();
|
||||
});
|
||||
return;
|
||||
@@ -629,6 +632,9 @@ function startStaticWebServer(distRoot: string, port: number) {
|
||||
response.setHeader("Content-Type", contentTypeFor(targetPath));
|
||||
response.setHeader("X-Content-Type-Options", "nosniff");
|
||||
response.setHeader("Content-Length", String(content.byteLength));
|
||||
if (targetPath.endsWith(".html")) {
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
}
|
||||
response.end(content);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user