Fixed If modfied since logic
This commit is contained in:
parent
cbbf0e5e3b
commit
246cdb4af0
|
@ -8,10 +8,14 @@ export const pageCachingMiddleware = defineMiddleware(async ({ url, request, loc
|
||||||
const cachedPage = pageCache.get(pathname);
|
const cachedPage = pageCache.get(pathname);
|
||||||
|
|
||||||
if (cachedPage) {
|
if (cachedPage) {
|
||||||
const modifiedSince = request.headers.get("If-Modified-Since");
|
const clientTimestamp = request.headers.get("If-Modified-Since");
|
||||||
const lastModified = cachedPage.headers.get("Last-Modified");
|
const serverTimestamp = cachedPage.headers.get("Last-Modified");
|
||||||
|
|
||||||
if (modifiedSince && lastModified && new Date(modifiedSince) <= new Date(lastModified)) {
|
if (
|
||||||
|
clientTimestamp &&
|
||||||
|
serverTimestamp &&
|
||||||
|
new Date(clientTimestamp) == new Date(serverTimestamp)
|
||||||
|
) {
|
||||||
return new Response(null, { status: 304, statusText: "Not Modified" });
|
return new Response(null, { status: 304, statusText: "Not Modified" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue