Return 404 when page not found

Currently, when a page is not found, the dash user guide suggests passing a 404 as the app layout using the pathname callback.
However, in my opinion, this has a few problems:

  • A http 200 status code is returned for the request, rather than a 404
  • All the plotly/dash js/css is loaded by the client, just to show a 404 message - this consumes network bandwidth and puts extra load on the servers hosting the content (especially bad if hosting the content locally)

Is there anyway to pass a true 404 and skip loading all the css/js?
I’ve dug around editing the dash.Dash class but I couldn’t figure anything out.

This isn’t possible at the moment. I’ll leave this to @chriddyp to comment further if he has anything else to add, but I would suggest raising this as an issue at https://github.com/plotly/dash.

You can pass your own server instance into dash.Dash(server=server) and that server instance could have a custom 404 route.