| Snap-O-Meter - Web Performance Monitoring |
| Snap to It - Preloading made Easy |
How To Improve Page Load TimesThe Art of Web OptimizationImproving your sites page load times is not easy, and can be a bit of an art. Every web page is unique and appeals to a different audience. Optimization techniques that work well for sites with a global audience may actually have a negative effect for sites with a localized audience. Sites with just a few images will benefit more from certain techniques, while sites with lots of images will benefit from others. We've developed an online reporting solution to help make sense of it all and prove what's best for you. In this article we attempt to summarize these findings. Reducing the Number of Sub-Requests per Page
If there is one philosophy that you take away from this article it should be this: Optimizing Images for the InternetDifferent FormatsThere are four primary formats to choose from when optimizing images for the internet. Each format stores and compresses image information differently. These four main formats include PNG-8, PNG-24, GIF, and JPEG. Below we will discuss the different formats and what images they work best with. GIFThe GIF format is a bit-mapped image format and is the most commonly used format for web graphics. It supports up to 256 colors, transparency, and animation. Typically the PNG-8 format compresses better for most web images, although for really small images, or images that require transparency or animation, GIF is an ideal choice. JPEGThe JPEG format works well for photographs and other large images with many colors because of it's lossy compression algorithm. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. This often allows large images to be compressed more than any other format with little or no perceptible loss of image quality PNG-8The Portable Network Graphics is a bit-mapped image format that uses a loss-less data compression algorithm. It was designed to be a replacement for the patented GIF's. This format does not support transparency, translucency, or animation. This format is the best choice for most internet graphics. PNG-24PNG-8 and PNG-24 are the same format, however when transparency, translucency, or more than 256 colors are used, 24 bits are used to represent each pixel instead of 8. This increases the size of the image and can usually be avoided. If only transparency is required than use the GIF format instead. Also try to avoid translucency by flattening the images so that you can use an image format with less overhead. Choosing the Right FormatAdobe Photoshop has a nice feature within the "File -> Save for Web" function. It allows a nice 4-up view where you can compare the file size of three different image settings and compare the quality with the original. First compare the different formats GIF (with 256 colors), JPEG (high quality), or PNG-8 (with 256 colors) and decide which format is best suited for the given image based on the resulting image size. If JPEG is the best choice try to further compress the image by reducing the quality to an acceptable level. For PNG-8 or GIF images, try to compress the image further by reducing the number of colors used by the image. Often times you can reduce the number of colors down to 128, or even 64 colors, without any noticeable effect to the human eye.
Image Stacking (CSS Sprites)OverviewImage Stacking is a method of speeding web page delivery by combining separate images into one image, reducing the number of HTTP requests needed to load a web page. CSS is used to separate these stacked images back into individual images. This results in a web page that is visually identical but loads faster, because of a reduction in HTTP requests. On some web pages, all images can be combined into a single image, however there are several exceptions:
Implementing Image StackingFirst you must combine the images into a single image and then save it into an optimized format such as PNG-8, GIF, or JPEG. This will require graphic manipulation software such as Adobe Photoshop. Next you must include and split this image inside your web page. The trick involves a combination of the CSS attributes background-image, background-position, width, height, and overflow.
ExampleNow that we have covered the basic concept, let's dive into an example. The following html is a simple example with three div's each representing an image using standard CSS background attributes.
Here is the output of the HTML above
Next, we open Adobe Photoshop, or an alternative graphics manipulation application, and place the three 64x64 images side by side into one image 192x64
Now it's time to split the image using CSS. Note that the three div's use the same value for the background-image attribute, and have different background-position values.
The output is identical to the original output, but the number of http requests and the resulting page load time have been reduced.
Browser SupportAll modern browsers are supported including Internet Explorer (6,7,8), Firefox, Google Chrome, Safari, and Opera. Streamlining or Bundling CSS and JavaScript filesWhat is Streamlining?Streamlining is the act of taking external resources like CSS and JavaScript files that are loaded through separate http requests using <link> and/or <script src="..."> tags and displaying their contents inline within the HTML source. While this prevents these resources from being cached, it proves to be an effective optimization for workloads that have a low number of page views per visitor. Bundling Separate FilesSome sites may take a hit in performance, because their visitors typically view many pages. By streamlining these resources, they can no longer be cached on subsequent page views. By bundling separate CSS and JavaScript files into a single file, you can still cache the resources while reducing the number of http requests and improving page load time. HTTP CompressionHTTP Compression is a feature of the HTTP protocol that allows properly configured web servers to compress data to browsers that also support it. Typically HTML, CSS, and JavaScript will compress to 75 and 95 percent of its original size. This can save a ton of bandwidth for high volume sites, and would also seem to promote a faster loading page. We are unclear at this point as to whether this helps or hurts page load times. Logically it makes sense that this would help, especially for slower connections like modems and mobile devices. HTTP CachingHTTP Caching is a feature of the HTTP protocol that allows properly configured web servers to instruct web browsers to store copies of resources on their local machine. The next time a request is made for the same resource, the web browser will use the local copy instead of retrieving the resource from your web servers. While this will not help with the initial page view from a visitor, it can drastically reduce the load time of subsequent page views. ImplementingHTTP caching is accomplished through proper use of the Cache-control, Expires, and Proxy response headers. I recommend using the Cache-control and Proxy headers and not the Expires header. The Expires headers can misbehave if users or proxies do not have the correct time. To enable content to be cached for a week, specify the following response header.
If you want to prevent a resource from being cached by web browsers, use the following response header instead:
There are other useful options to the Cache-Control header. You can read about them in the HTTP/1.1 specification. SnappyJSnappyJ is a Java Library released under the GNUv2 license to ease the implementation of application-like web pages. It allows any section of your page to be reloaded outside of the content of the entire page. While this is possible using an AJAX request, below is a list of complications with using AJAX, that SnappyJ overcomes.
By reloading only a small section of your page instead of the entire contents, less data is transferred, less work must be done by the browser, and the browser doesn't jump to the top of the page, improving your visitor's user experience. Using a CDN (Content Delivery Network)The concept behind a content delivery network is simple. Cache and serve cache-able content from servers located closer to your end-user's location. This has become a crowded market and there are many players in the market. We put four popular CDN's to the test, and our findings where quite surprising. Every CDN we tested had similar results. Page loads in Europe were faster, almost twice as fast in some countries. Asia traffic was actually slower. In the United States, where performance was most important, the results were almost identical. Don't let the CDNs fool you with their Gomez and Keynote reports boasting substantial gains. Test the page load time of actual visitors and get the facts. GetSnappy.com CDN +OptimizerWe are in the process of testing a new breed of content delivery network. Caching objects can only improve performance so far. CDN +Optimizer takes a different approach and will cache and optimize your entire web application. By caching your entire site, and using proven optimization techniques discussed in this article, content is delivered faster than any competitor. This solution will also increase your high availability, utilizing DNS based failover and fallback to cache technologies. Help Us Make the Web FasterWant to help us make the web a faster place? Spread the word about this article by providing a link on your site or blog using the HTML below. <a href="http://www.getsnappy.com/web-optimization/improving-page-load-times.html">Tips and techniques to help reduce page load times.</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|