4 ms·
Yep, returning the wrong HTTP status code is going to confuse a lot of search engines, chat app link previews, and other automated consumers of your SPA, even i
by kijin 3y ago
Yep, returning the wrong HTTP status code is going to confuse a lot of search engines, chat app link previews, and other automated consumers of your SPA, even if you subsequently display the correct error page.
- leptons 3y ago>returning the wrong HTTP status code is going to confuse a lot of search engines How is the search engine going to find a page that doesn't exist, isn't in a sitemap, isn't linked to in any nav anchors, in order to index it?
- traverseda 3y agoI will submit it to google to be indexed myself, purely out of spite for the fact that you're willfully and with malice aforethought returning 200 when you know you should be returning a 404.
- treve 3y agoPerhaps the page existed in the past but now it doesn't. Or at some point a link was misspelled.
- shkkmo 3y ago> How is the search engine going to find a page that doesn't exist, isn't in a sitemap, isn't linked to in any nav anchors, in order to index it? If links are never going to be used, there is no point in doing the effort of client side routing. If links are going to used, the server needs to respond with the correct status or you break the assumptions upon which the tools people use to access the web are based.
- leptons 3y agoThe article is about serving SPAs. In SPAs the "pages" are not really pages, they are program state. Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. If you're scraping my site or something, then too bad for you. The SPA server is under no obligation to serve any page with any specific response code so long as it is valid HTTP.
- shkkmo 3y ago> Just because you think /whatever shouldn't go to the homepage doesn't mean your way is the best way for an SPA to work. Maybe I'd rather display the current sale instead of a generic "404" error. Nothing wrong with that. I Return a non-200 response doesn't mean you can't return a page. You can indeed display the current sale in the content returned with a 404 response and most sites do. A SPA absolutely can return tue full index.html content for every end point, but it shouldn't lie with it's status codes in the process. > The SPA server is under no obligation to serve any page with any specific response code so long as it is valid HTTP. You are also under no obligation to close your html tags or accessibility guidelines. However, ignoring specs like this can break things for your users in ways you can't always predict, especially for more marginal use cases. If you're gonna to write a SPA, please, I beg to you, actually take the time to do it properly and release tools that enable that. Otherwise you are directly contributing to making the internet worse.
- leptons 3y ago>Otherwise you are directly contributing to making the internet worse. I don't think it really matters as much as you say it matters. It isn't "making the internet worse", it's only affecting the specific site's indexing, so don't act like this happening is bleeding out to other sites and affecting everyone. Calm down, "the internet" isn't getting worse from this practice. >A SPA absolutely can return tue full index.html content for every end point, but it shouldn't lie with it's status codes in the process. That's your opinion. I'm fine with it returning a 200. The thing about SPAs is "the server" doesn't always know if a route is valid or invalid. Hosting an SPA on S3 is one example of that. It responds to requests made to unfound resources with the index page, and a 200 status. It does not know if /account or /config does or does not exist in the front-end routing, the server is dumb and can only serve assets that it knows exist. So it returns the content for the index page and the front-end then decides if the route is valid or not, because the front end state changes with the URL, and there could be thousands or billions of different routes, especially if data is included in the route. There is no way to set up the server to know every route that might happen when it encounters something like /account/verify/8ab2c09f43e7b2a094839ab3cef329 In this case the back end serves index.html with status 200 and the front-end sorts out what to do. And I'm fine with it, this doesn't "make the internet worse", only the SPA site is affected (if it really has any effect at all). You can serve pages on your site however you want to, I don't really care what your site does.
- floydnoel 3y agoeasy enough to solve with Prerender. when using it I include some head tags to allow the Prerender server to send codes like 404 or 301. It's worked well for SEO compatibility, I even wrote a small React router project to handle this situation automatically (as well as other TSEO considerations like trailing vs non-trailing slashes).