Everything about Web and Network Monitoring

Home > Industry Info > Application Performance Management > Best Ways To Optimize a Website While Using a CDN

Best Ways To Optimize a Website While Using a CDN

Content delivery networks are one of the best ways to increase the speed of a website. They allow website owners to use a massive amount of resources, typically scattered throughout many regions of the world, to transfer their site’s files to their end users. When a user connects to a website using a CDN, the CDN checks to see if the file they are downloading is close to their proximity. If it is not, the file is sent to a server that is close to the visitor. This ensures that the next time a visitor from a surrounding location visits the site, they are served content from a close location. This will greatly increase the visitor’s download speed, which allows the website to load much faster. While this technology was only accessible to big businesses, providers are now able to offer much cheaper prices to small businesses and website owners. Now, every website can utilize a CDN to serve their static files. However, before placing files on a CDN, there are ways to ensure that they are in optimal condition for fast download speeds.

Optimizing Files For Optimal Download Speeds

CDN providers have ensured that their networks are optimized to the highest standards possible. While they will serve a site’s files swiftly, there are a few things website owners can do to increase the download speed of files placed on a CDN. ¬†Whether a website is utilizing an ecommerce store for their sales or have an established application that visitors use, these practices can be employed to greatly increase downloading speeds. Websites use content delivery networks for mainly five types of files: images, stylesheets, scripts, Flash and large files meant for downloading.

Image Compression

Many images that are uploaded to the web are not properly compressed. This might not seem like an immediate concern, but saving an image for the web can greatly reduce its size while maintaining the image’s quality. In fact, <a href=”http://www.smushit.com/ysmush.it/”>Smush.it</a>, a Yahoo! owned website, offers image compression for free and it is very user friendly. Users can either upload their files or send a list of URLs to Smush.it and download the files after they are compressed. While uploading four uncompressed pictures straight from a digital camera to Smush.it, I saw an average savings of 17%. The largest savings was 20% where an image with a 598.02 KB size was compressed down to 446.38 KB.

Image Compression For Apps

Oftentimes, web applications will allow users to upload images to their servers. While this is a very convenient and popular feature, images are often uploaded without being compressed. However, many image libraries such as ImageMagick have libraries for many different programming languages. For instance, when a user uploads an image, a PHP script can use an ImageMagick library to resize and compress the image. This will allow uploaded images to scale to the website’s predefined dimensions, while reducing downloading speeds.

File Compression

Large files are often available for downloading and can include documents, videos or even company reports. While these files will not alter a site’s speed, they are often sent to a CDN for faster downloading speeds. It is a good practice to zip up any files that can be zipped. <a href=”http://office.microsoft.com/en-us/help/zip-or-unzip-a-file-HA001127690.aspx”>Microsoft</a> states that zipping a file can reduce its file size by up to 80 percent. This means that download times can be reduced by 80 percent and data transfer costs are also reduced. Many operating systems include a compression program and can be utilized for free. If a web application allows users to upload various types of files, these files should be compressed. Many programming libraries include compression functionality and should be implemented for optimal transfer speeds and storage reduction.

Use CSS Image Sprites

Image sprites are used to combine many small images into one bigger image. While this might seem like an odd thing to do, it is one of the <a href=”http://developer.yahoo.com/performance/rules.html/”>performance rules</a> set by Yahoo!. If 10 images are included in one sprite, this will reduce the HTTP requests sent from 10 to 1. This greatly increases a site’s speed and should be used in conjunction with a CDN.

Minify CSS and Javascript Files

Virtually every website utilizes CSS stylesheets and Javascript files to make their site more user friendly. While these files might not seem large, they are just another area of wasted file space. Commenting and spaces account for a large portion of the wasted space, but are essential for maintaining these files properly. However, it is possible to minify these files to greatly reduce their size. <a href=”http://developer.yahoo.com/yui/compressor/css.html”>Yahoo!</a> offers a CSS minifier for absolutely free and explains exactly how their compression works. <a href=”http://jscompress.com/”>JSCompress</a> is an equivalent free service made for Javascript files. This type of compression should be made to all CSS and Javascript scripts before they are uploaded to a CDN.

Use Subdomains to Optimize Requests

The coding standard followed by most web browsers is HTTP 1.1. This standard dictates that only two connections can be active for each hostname. This means that if a website has 10 images to be loaded, only two of them can be downloaded in parallel. However, this greatly decreases the downloading speed because more often than not, files reside on the website’s main host. Google <a href=”https://developers.google.com/speed/docs/best-practices/rtt#ParallelizeDownloads”>recommends</a> that files be split up on subdomains. For instance, a site might serve up all images from cdn1.site.com and all other CSS and scripting files from cdn2.site.com. This would allow more than two files to be downloaded in parallel because they are all being downloaded from a different hostname. It should be noted that each hostname would ideally share an even amount of the load. So if four hostnames are present, ideally, they would all have 25 percent of the needed files.

Setting a Default Cache Time

Many CDN providers will allow users to set a default cache time. This allows files that are not frequently changed, such as image logos, to be cached for a much longer time. The only issue with this is that the same file name cannot be reused until all user caches have expired. Following <a href=”http://developer.yahoo.com/performance/rules.html”>Yahoo’s best practices</a>, it is recommended that new files, such as CSS stylesheets be renamed sequentially where style1.css will be renamed to style2.css and so on. By using this practice, a user’s browser will cache the files much longer. This reduces bandwidth usage and site speed dramatically.
Small and large websites can utilize a content delivery network to make their user’s experience much better. While uploading a file to a CDN is a good start, ensuring that it is properly compressed will lower its file size and downloading time further. It is always important that websites optimize their site’s speed to further their user’s retention.

About zhirayr