Return 204 without using bundled request

Is there any way to make a specific path return a 204 without using up bundled requests? this is my current solution as a function:
export function onRequest(context) {
return new Response(null, {
status: 204,
});
}
export function onRequest(context) {
return new Response(null, {
status: 204,
});
}
6 Replies
Sebastian
SebastianOP2y ago
i use that on /favicon.ico
James
James2y ago
I believe using a Function as you have there is the only real way to do that today You can alter headers with _headers without a Function, but not the response status code Out of interest, what's your use-case to need to do this and explicitly return an empty response with a 204 for the favicon?
Sebastian
SebastianOP2y ago
i don't have a favicon, and it's not an error that i don't have a favicon so why return a 404
kian
kian2y ago
Because 404 is Not Found, and you don't have a favicon, so it's not found 404 isn't necessarily a bad thing
Sebastian
SebastianOP2y ago
right, and i think that makes sense for every single request that i'm not actually expecting but i know for a fact that a browser is going to request a favicon and i know i don't have one so might as well tell the browser that instead of "dunno"
Erisa
Erisa2y ago
i would have thought the most spec-compliant way to tell the browser you dont have a favicon.ico file is to return 404 it seems the closest you can get is creating an empty file named favicon.ico in your output, which will return 200 with no content, sadly not 204 https://cf464749.erisa-uk-test.pages.dev/favicon.ico saves the bytes consumed transmitting your 404 page and its not used as a favicon because an empty file is not a valid image so if thats what you need... why not
Want results from more Discord servers?
Add your server