Posts Tagged ‘website’

Get Info On Domains With WolframAlpha

Saturday, May 16th, 2009

Did you know that WolframAlpha allows you to get info on specific websites and domains?

It’s quite easy as you just need to enter the domain name into the search field. Most of the data seems to have been retrieved from Alexa but it’s still a great idea. I still don’t understand the HTML element hierarchy graph but it looks interesting. However I don’t know what the tag information could be used for.

The following image shows the info WolframAlpha shows currently for this blog. And I think I need to say that the number of visitors is a bit far off ;-)

WolframAlpha Sascha Kimmel

How To Achieve Maximum Website Performance (Part 3)

Sunday, May 10th, 2009

Welcome to part 3 of this article series on how to maximize the performance of you website. This time I am going to show you how to minimize the number of HTTP requests on your page. Most people don’t even realize how many HTTP requests are required until every single element on the page has been loaded. I was shocked when I saw that the Sociable plugin for Wordpress has not been optimized for the number of requests but more on that later.

4. Less Requests = Better

If you have not done yet you need to empty your browser cache once again. Open the page you wish to optimize and open Firebug by clicking on the Firebug icon in your browser’s status bar.

Firebug

Firebug

If you have not used Firebug before on that domain you need to activate it (check all boxes) and reload the page. After the page has finished loading open the network tab in Firebug at the top.

This will show you all of the HTTP requests that were required on your page.

Using CSS Sprites To Reduce Image Requests

Now have a look at all of the image requests on your page. If you move your mouse pointer over the “GET …” text on the left hand side of the list Firebug will show you a thumbnail version of the image so that you can find out quickly which image has been loaded.

On my blog (this page) there is a large number of images loaded which can (and should) be optimized.

Some of the HTTP Image requests on my blog

Some of the HTTP Image requests on my blog

There is a good technique to merge several images into one file yet still be able to display separate images even in separate image tags in HTML. These are called CSS Sprites because Cascading Style Sheets are used to implement this. In fact a new image is created that contains all of the images and CSS is used later with background positions to show separate areas of the image where the source images are located in the merged image.

This is not as hard as it sounds because although you could create the merged image and CSS manually I prefer to use the Online CSS Sprite Generator.

The only thing you need to do is to package all of the images into a single ZIP file and upload it on the Sprite generator website. I recommend that you use the same output format as the original images - I will be using the PNG format. You may want to change some of the default options however I am using the default options most of the time.

After clicking on the “Create Sprite Image & CSS” button after a few seconds you will be shown some CSS code and a link to download your merged image.

In my case I received the following CSS code:

.sprite-1_de_btn { background-position: 0 -30px; } 
.sprite-delicious-large_blue { background-position: 0 -83px; } 
.sprite-digg-large_blue { background-position: 0 -165px; } 
.sprite-findmeonfacebook2 { background-position: 0 -247px; } 
.sprite-linkedin2 { background-position: 0 -310px; } 
.sprite-myspace1 { background-position: 0 -370px; } 
.sprite-stumbleupon_48x48 { background-position: 0 -460px; }

This is the code I have added (slightly modified from the original code on the website):

.sidebarsprite {background: url(/img/csg-4a07143404186.png) no-repeat top left; }

This is the merged image:

Merged Buttons as CSS Sprites

As I am not using a list for the images on the right hand side of this page (the sidebar) although this may make sense this is how I implemented it. You need to have a 1×1 pixel transparent GIF first. This will be used as your main image file in the image tag and it has to be transparent for the background image to be visible.

<img src="/img/spacer.gif" width="100" height="30" alt="" border="0" class="sidebarsprite sprite-linkedin2" />

When using an image tag (and not an <li> tag) you have to set both width and height of the image as shown in the image tag above otherwise your image will not be shown.

It does of course not make sense to merge all of the images on your page just to save HTTP requests but you should do this whenever there are images on your page that are used on many other pages on your site as well (just like the sidebar images I am using).

By using the CSS sprite technique just described I have saved 6 HTTP requests to the server. There is even more to optimize - try it for yourself on your own website.

External Scripts Under Scrutiny

Now it’s time to have a look at all the external scripts and maybe images used on your site. Use the method described above in Firebug to find more culprits. And look very closely at your own website - do you really need these 12 external JavaScripts to show your Twitter follower count, your social network friends and contacts and so on?

By using Firebug you can find out how much further requests are caused by some of the external scripts - just scroll down the list in the network tab.

Remove all of the external files that are not essential and that you can live without.

Merge CSS And JavaScript Files Automatically

If you have several CSS and/or JavaScript files on your page hosted on your own server you should merge them into a single file - for your visitors. I strongly suggest to keep modular code separated on the development site but you may wish to just copy all of your own JavaScript and CSS files each into a single .js and a single .css file while still keeping the original files for editing.

Also see the section Optimizing CSS and JS Code in part two of this article series.

Several techniques are shown on this page but I am planning to show you the one I am using in one of the next articles on my blog.

Outsourcing With Google

If you are using one of the popular JavaScript frameworks like prototype.js, jQuery, MooTools, DoJo, script.aculo.us etc. I suggest using Google to deliver these files straight from their servers. Google’s worldwide network of servers has a very high performance and speed so I suggest you check out the documentation on the AJAX Libraries API and start using it to deliver these files through Google’s servers.

This concludes the third part of this article series. Continue with the next part.

tweetthis-15

How To Achieve Maximum Website Performance (Part 2)

Sunday, May 10th, 2009

This is the second article in the article series on how to maximize your website performance. I assume that you have also read the previous article which defines the basics of performance optimization.

After optimizing the time to the first byte received the next step is to decrease the load time of your website.

3. Decreasing Load Time

The less bytes are to be transferred the better. But you may also want to check your webhost first because if the connection to your server is very slow that might be the root of the problem - not necessarily the number of bytes to be transferred.

Checking Your Server Performance

To check this you should upload a large file to your server - maybe 10 megabytes at the very least - the larger the better. You should also ensure that your own internet connection does not suffer from any problems while you are testing. All downloads and other programs (like email clients) should be shutdown prior to testing.

Please note that this test only shows the maximum speed of both your server and your own internet connection combined. If your server is connected to the network with 100 Mbps but your internet connection is just 1 Mbps you will only be able to measure 1 Mbps as the maximum speed so depending on your connections it may not make sense to measure the speed.

Now you need to have a stopwatch ready as you need to measure the time from starting the download to the download being finished. Let’s say the file you have uploaded has a size of 2 MB. You now have to divide the file size by the number of seconds it took to download. If it took 10 seconds to download the file the connection speed is something like 2MB/10 seconds = 0.2 Mbps = 200k/s.

You may also use DownTester (freeware) to measure the download speed automatically.

To measure the performance of your internet connection I recommend using SpeedTest.

If you have found out that the server speed is indeed very low compared with what you would expect check back with your webhost.

Image Optimization

Now it’s time to review the images on your page. Select “Images” > “View Image Information” in your Web Developer Toolbar after you have opened your website again in your Firefox browser.

webdeveloper

This will open a new tab which will list all of the images on your website including information on image dimensions, URL and file size. Have a careful look at the number of total image requests - the higher the more you can optimize.

webdeveloper-image-count

While scrolling down always have a look at the file size for each image. There is not a rule of thumb regarding the file size of an image because it depends on the file type of the image and the dimensions.

Image Types - What’s Right And What’s Wrong

I am still amazed when I see how many web developers still do not know which image file formats to use for different kinds of images. There are only three main types of images used on the web (yes, I won’t talk about SVG and other formats here) and supported by all major browsers:

  • GIF
    The GIF format should never ever be used to compress photos because it has been developed for images with a maximum of 256 colors and works best with images that contains a small number of colors and especially large chunks of pixels with the same color.
    This is the optimal format for screenshots of an application and for graphics with a small number of different colors.
    When compressing GIF images you can choose the maximum number of colors. Sometimes just 16 colors or even just two may be enough however in my opinion you should not invest hours to optimize images just to gain a total 10 KB out of it.
    Supports one color to be used as a transparent color. Supports animations as well.
  • JPEG
    The JPEG format (the “P” actually stands for “photographic”) has been developed for true-color images, mostly for photos. It should never be used for screenshots beause it uses far more storage capacity (and therefore load time) than required.
    No support for a transparent color, no support for animations.
  • PNG
    Nowadays PNG files - although originally developed to be used online - are seldom used for normal images on a website. From my experience it does not make sense to use PNG graphics most of the time except you want to use the so-called alpha transparency feature which in contrast to the GIF transparency offers a full 256 bits channel for transparency. This means that you cannot only pick one single color that is transparent but several grey scale values which are semi-transparent. This allows for seamless integration onto any background.
    Most of the time I am only using PNG images if I need alpha transparency.
    There are currently two formats implementing animations for PNG.

Sample Images - Learning By Seeing

Just have a look at the following images to see the differences in image types and compression. You should see very clearly when not to use JPEGs and prefer GIF images instead.

Photo (bad, saved as GIF, 32K)

Photo (bad, saved as GIF, 32K)

Photo (good, saved as JPEG, 21K)

Photo (good, saved as JPEG, 21K)


Screenshot (good, saved as GIF, 5K)

Screenshot (good, saved as GIF, 5K)

Screenshot (bad, saved as JPEG, 15K)

Screenshot (bad, saved as JPEG, 15K)


Screenshot (good, saved as GIF, 5K)

Screenshot (good, saved as GIF, 5K)

Screenshot (bad, saved as JPEG, 8K)

Screenshot (bad, saved as JPEG (90%), 8K)


Screenshot (good, saved as GIF (8 colors), 2K)

Screenshot (good, saved as GIF (8 colors), 2K)

Screenshot (bad, saved as JPEG (20%), 3K)

Screenshot (bad, saved as JPEG (20%), 3K, still larger than the GIF)


Screenshot (good, saves as PNG (truecolor), 4K)

Screenshot (good, saves as PNG (truecolor), 4K)



You should have seen that GIF offers good quality and still requires less bytes for certain images.

After you have optimized your images (Corel PhotoImpact offers a very cool image optimization assistant for JPEG, GIF and PNG) now it’s time to look at your CSS and JS code on the page.

Optimizing CSS and JS code

Are you using Cascading Style Sheets (CSS) and JavaScript on your page? For this optimization it does not matter whether the code is embedded on your website or has been outsourced to an external file. Just look at your CSS and JavaScript code and remove unnecessary comments first.

Now it’s time to compress your CSS and JavaScript files. There are free online services available to compress CSS and JS code. I recommend using CSSDrive to compress your CSS code and JavaScriptCompressor.com to compress your JavaScript code.

You should save the compressed code to another file than your original file otherwise you won’t be able to edit the code later on unless you are a bot of course.
Just remember that you have to repeat this process every time you modify your CSS or JS code. In a later article I will show how you can automate this process completely with PHP.

Cleaning Up The HTML Code

Now have a closer look at your HTML code. Are there large chunks of code in comments? Remove the comments that are no longer useful.

Embedded Code From External Domains

Is there any popular website that doesn’t offer embeddable content? Yes, embeddable content can be quite cool but it may also slow down the loading time of your page especially if the code snippet you have inserted into your page uses JavaScript because your browser will stop rendering the page right where the JavaScript code has been embedded until it has been executed successfully. If an external source is unavailable or very slow your page will get stuck while loading.

I even had to remove some ad server code some months ago from one of my pages because the ad server was so slow that even after one minute my page was still showing just half of the page rendered. This is not an impressive or professional view. It makes you look like an amateur.

To find out which sources are slow you only have to look at the status bar of your browser to see what is currently happening. “Waiting for ….” is an indication.

Sometimes I also experience slower load times on my page because of the Google Friend Connect Widget embedded on the sidebar to the right. You should check the code one-by-one and decide if you really need this specific widget, snippet or feature.

There are many sites that allow you to embed buttons on your own website to link to your Twitter, Facebook, LinkedIn, MySpace etc. profile and just give you a JavaScript snippet to put onto your site. You should think about using static images to upload onto your server and link to the pages manually.

This concludes the second part of the article series. The next part will focus on how to minimize the number of requests on your page. Some of the optimizations discussed in this article will be revisited to further improve the performance of your website. Click to read the next part now.

tweetthis-15