Reduce server load by using a trailing slash in URLs

Reduce server loadA while ago I came across this small tip in an online conversation. It might not be a huge thing, but it can have an impact if you have a site with lots of traffic.

80% of the end-user response time on a website is spent on the front-end. Most of this time is tied up in downloading all the components in the page: Images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.

One thing which can increase load-time in a website is the way redirects are handled.

This quote from Yahoo.com describes the problem:

Redirects are accomplished using the 301 and 302 status codes. Here's an example of the HTTP headers in a 301 response:

HTTP/1.1 301 Moved Permanently
Location: http://example.com/newuri
Content-Type: text/html

The browser automatically takes the user to the URL specified in the Location field. All the information necessary for a redirect is in the headers. The body of the response is typically empty. Despite their names, neither a 301 nor a 302 response is cached in practice unless additional headers, such as Expires or Cache-Control, indicate it should be. The meta refresh tag and JavaScript are other ways to direct users to a different URL, but if you must do a redirect, the preferred technique is to use the standard 3xx HTTP status codes, primarily to ensure the back button works correctly.

The main thing to remember is that redirects slow down the user experience. Inserting a redirect between the user and the HTML document delays everything in the page since nothing in the page can be rendered and no components can start being downloaded until the HTML document has arrived.

One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to http://astrology.yahoo.com/astrology results in a 301 response containing a redirect to http://astrology.yahoo.com/astrology/ (notice the added trailing slash). This is fixed in Apache by using Alias or mod_rewrite, or the DirectorySlash directive if you're using Apache handlers.

So instead of linking to a page like http://astrology.yahoo.com/astrology, link to http://astrology.yahoo.com/astrology/. Otherwise, the server will do an automatic redirect to the latter link. And that slows down the response time of the site.
Read more about optimizing your page load speed over at Yahoo.com: Best Practices for Speeding Up Your Web Site
Read 11063 times Originally published on Saturday, 10 April 2010 14:00
Last modified on Tuesday, 31 January 2012 13:56
 
comments powered by Disqus