How to Avoid a Bad Request

bad request

What is a Bad Request?

A bad request occurs when a resource that doesn’t exist or is malformed is initiated by a separate resource or clicked by a user. These types of requests are not only a hassle for the user who is requesting a resource which doesn’t exist, but can also increase page loading times. For example, if an HTML page is initiating a CSS file who’s file path has changed, an additional round trip may be needed as the server attempts to fetch the resources which is no longer at the specified location.

According to Wikipedia, the 400 bad request HTTP status code is define as,

The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

The 400 status code may be triggered for a variety of reasons most commonly due to an issue on the client side. However, when running your website through a site speed test tool, the “Avoid Bad Requests” recommendation is referencing broken links within the actual website.

HTTP Status Code 404 / 410

The 404 Not Found error message indicates that the requested URL could not be found on the server however, it may be available again in the future. It can occur if a particular URL is published, however the permalink later changes. If the old URL is embedded as a link somewhere on your website, users will be returned with a broken, or dead 404 Not Found error.

A 410 Gone bad request error will also be flagged by a site speed test tool as it unnecessarily uses resources. A 410 error means that the request URL no longer lives at the specified location and is essentially a dead-end.

Finding these broken links and rectifying the issue by either correcting the URL or removing the link entirely helps ensure that your visitors are being directed to the proper information. This also guarantees that there are no wasted resources due to bad requests. It should also be noted that performing a 301 redirect on a broken link is not good practice. Redirects contribute to a higher page loading time, therefore not entirely fixing the issue of a bad request.

Avoiding Bad Requests

It may not always be apparent to the website owner that a bad request is occurring on their website. However, there are a few options available to help ensure that you avoid bad requests. Certain site speed tests such as Gtmetrix and Pingdom identify if your website is returning any bad requests and notifies you which URLs need to be fixed. For example, by purposely altering the url of a resource to produce a 404 error, Gtmetrix identified this URL as a bad request.

bad request example

Additionally, broken links can be verified in your Google Search Console by navigating to Crawl > Crawl Errors > URL Errors. This page will display any crawl errors that the Google Search bot experienced while trying to crawl your site. It’s good to keep an eye on this page in case that any errors do occur which can then be properly handled either by fixing the link or removing it entirely.

Being aware of any bad requests by periodically running a site speed test or checking your Google Search Console page is important. This helps not only ensure that your users won’t get frustrated when trying to access a link and receive a 404 error, however it will also help reduce the amount of wasted resources required to fetch a non-existent resource.

Leave A Comment?