Next.js Discord

Discord Forum

404 response for file requests

Unanswered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
Hi everyone! I am trying to reduce the amount of bandwidth that my site uses, specifically when responding to requests for files which do not exist (either bot requests or requests for js files with invalid/outdated hashes).

The issue is that when a file is requested (eg. /does-not-exist.js) the html for the 404 page is returned.

Is it possible to return a json response to unfulfilled file requests instead of the not-found page?

2 Replies

@Rhinelander
make the notFound.jsx page redirect to an api route which you return json with