This is part of our series on using Yslow to improve website speed. Today, I am going to focus on the server level items than can help you improve your site speed.
Yslow Server Recommendations
Under the server tab in YSlow, you will find the following items:
- Content Delivery Network
- Avoid empty src or href
- Add Expires Headers
- Entity Tags
- Ajax Optimization
A major focus of server side optimization is to reduce the load on the server. One of the key metrics I like to pay attention to is the number of HTTP requests/sec that the server can handle.
Many of the techniques below focus on reducing the number of requests a web page has to make to the server. Reducing these requests makes your website load faster while reducing server load. By reducing the number of requests per page, your server may be capable of handling more simultaneous users or handling more requests from the same user more quickly. This could reduce website load times or keep your site running quickly at peak traffic.
Content Delivery Network
Most sites will not need a content delivery network (CDN). CDN’s distribute static content to various locations worldwide. Users can then fetch the content from the nearest node instead of going to your server. This is very useful for sites with a lot of graphics, video or other rich, cacheable content.
Avoid empty src or href
You may think not specifying a href or src URL would cause a browser not to do anything. But actually, it treats it as a relative URL and tries to fetch a result. On a busy page, this could send many unnecessary HTTP requests.
I find this problem happens most with dynamic sites where a URL does not get inserted into the code for some reason. If this is happening on your site, get it fixed.
For more on this topic, check out this article on how empty image src can destroy your site.
Add Expires Headers
This is one of the easiest things you can do. By adding explicit expire headers, you can have your user’s browser cache content locally. Most servers should have expires enabled, but if not, you may have to have Apache reconfigured. Once you have Expires enabled, you can then add some settings to an htaccess file:
This is the format I like to use, but consult the mod_expires documentation for full details:
ExpiresActive On ExpiresByType text/html "access plus 10 weeks" ExpiresByType image/gif "access plus 1 day"
There are more optimal expires settings but this approach is easy to use.
If your content does not change often, I recommend setting far lived (years). I recommend setting a default at the top level of your site and then put htaccess into directories if you need to change these defaults. Some dynamic pages that update often may need immediate expiry dates, so you can set those explicitly.
You can use this cacheability checker to see how much of your page can be cached.
Most browsers have the ability to support compressed content. If you have ever unpacked a zip archive, then you have dealt with compressed content.
Apache, PHP and other tools can compress content on the fly. Instead of sending a HTML file, the system sends a compressed version which your browser decompresses. This can result in significant bandwidth savings and speed up your pages.
To enable compression, you may need to make some server level changes. Sometimes you cannot enable compression within an htaccess file due to security restrictions. If you can, you can try these entries:
# Or, compress certain file types by extension: <Files *.html> SetOutputFilter DEFLATE </Files>
Do not use this method to compress images. For images, you should just compress the file. Also be careful of applications that may do compression on their own. WordPress, Vbulletin and many other PHP applications can also compress content. There is no benefit from double compression.
You can test if your server is compressing content with this HTTP compression test.
From the server side, an HTTP request for a large file takes longer to fulfill than for a small one. So with the same level of traffic, compression can reduce the average number of requests per second. Also, this can reduce the number of simultaneous connections to the server. While there may be some processing overhead with compression, I find the benefit to the user outweighs the server impact.
Entity Tags (ETags) are used to help browsers determine if a file has been updated. The mechanism is more flexible and accurate than simply looking at a last-modified date. By using other file attributes, browsers identify changed content and update the cached material.
From a performance standpoint, I do not think this makes too much of a difference except on the busiest of sites. Also, if you are load balancing, you will need to turn them off as it will make client-side caching even less effective.
So the short take here is not to worry about them. If you really want to assure they are on, you can use:
In your htaccess files. This will disable them completely. I see various reports about if they should be on or off and have yet to fully explore their impact on server metrics or HTTP requests.
Optimizing AJAX is a topic in itself. This is more of a programming issue than a server side issue, so I will not dig into it here. If you are using AJAX on your site, then ask your programmers to assure that they use the HTTP GET instead of the POST method.
AJAX typically increases the average number of requests/sec to the server. If you add AJAX to a busy site, you may suddenly see performance problems due to high numbers of request. Also, logging of all of these requests can strain disks.
- Fix Slow Loading Websites – Yslow Image Tips
- Speed up Your Site – Yslow Server Tips
Speed Up Your Site
I hope that this helps you speed up your site. There are certainly other server-side optimizations you can do but I wanted to focus on Yslow’s recommendations since the tool is widely used.
Let me know if you have any questions or tips for the server recommendations offered by Yslow. Making your web site fast is becoming increasingly important as users tolerate slow sites less and Google now uses site speed in the SERPs.