Reduce server load by using a trailing slash in URLs

. Posted in Web tips - General web tips

A 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

Want more information like this?

Subscribe to my weekly Joomla newsletter.

When you sign up, you'll get a FREE 52-page ebook: The best of Joomlablogger.net

Kristoffer Sandven, JoomlaBlogger Written on Saturday, 10 April 2010 15:00
by

Viewed 4496 times so far.

Comment Rules: Critical is fine, but if you're rude, I'll delete your stuff. Please do not put your URL in the comment text unless it's relevant to the post and please use your PERSONAL name, blogger name or initials and not your business name, as the latter comes off like spam. Have fun and thanks for adding to the conversation!

blog comments powered by Disqus

Powered by Joomla

Joomlablogger.net is hosted by Rochen:

Rochen logo

Download Joomla for free