You are in: Home > Articles > 10 New Ways to Speed up Download Time | ||
10 New Ways to Speed up Download Time1. Avoid tables for layoutHere are six reasons why pages that use CSS for layout download faster than tabular pages:
2. Don't use images to display textIt's our old friend CSS to the rescue again. There's no need to use images to display text as so much can be accomplished through CSS. Have a look at this code:
This will give you a really simple button that appears to be pushed down when you mouseover it - See it in action if you like. To find just how far you can take this concept check out the CSS articles at A List Apart. 3. Call up images through CSSIt's possible to present images as part of the background, called up through CSS. If you've got an image that's 200px by 100px you can use the following HTML code:
And this CSS:
This may at first seem a little pointless but this technique could really increase the download time of your pages. Browsers basically download background images after everything else. By using this technique, your text will load instantaneously and your site users can freely roam about the page while your 50kb fancy image downloads. This technique is absolutely fine for decorational images that are effectively just screen furniture. However, if the image is part of the content, you need still need to use the IMG or OBJECT tag to apply it to the document. You could use an IMG with the above class and a transparent image as the src, but that represents an accessibility issue, as the user needs to have your CSS enabled to reach the image content. 4. Use contextual selectorsThis is inefficient:
Instead of assigning a value to each individual paragraph, we can nest them within a
This second CSS example basically says that
every paragraph within At first glance this doesn't look too important, but if you can apply this properly throughout your document you can easily knock off 20% of the file size. You may have noticed the colour values are shorter than normal. #03c is a shortened version of #0033cc - you can assign this abbreviated value to any colour value like this. 5. Use shorthand CSS propertiesFontUse:
...instead of
BorderUse:
...instead of
BackgroundUse: background: #fff url(image.gif) no-repeat top left
...instead of
Margin, padding, borderUse:
...instead of
Use:
...instead of
Use:
...instead of
These rules can be applied to 6. Minimise white space, line breaks and comment tagsEvery single letter or space in your HTML and CSS code takes up one byte. It doesn't sound like much but it all adds up. Don't hit return so often, don't indent lines and squash up those stylesheet rules together. You may need proper linebreaks and indentation to keep the code maintainable (for example when several developers work on the same documents). In this case you could think of a tool that strips unneccessary whitespace only when the documents get published to the live site. 7. Use relative call-upsNever use an absolute call up as it takes up more space, and more importantly, takes the
browser longer to download the page. An example of an absolute call up
is:
8. Remove unnecessary META tags and META contentMost META tags are completely unnecessary and do nothing. If you're interested, you can see a list of META tags that are available. The most important tags for search engine optimisation are the keywords and description tags, although due to mass abuse these have lost a lot of importance in recent times. When using these META tags try to keep the content for each under 200 characters - anything more increases the size of your pages. Lengthy META tags aren't good for search engines anyway because they dilute your keywords. 9. Put CSS and JavaScript into external documentsWe all know to do this, yet we so often don't do it! To place CSS in an external document use:
To place JavaScript in an external document use:
Any external file is called up just once and then cached on the user's computer. Instead of repeating JavaScript or CSS over and over again in HTML files, just write it out once in an external document. And don't forget, there's no limit to the number of these external documents that you can use! Instead of making one huge CSS document, have one main one and some others that are specific to certain areas of your site. 10. Use / at the end of directory linksDon't do this: Do this instead: Why? If there's no slash at the end of the URL the browser doesn't know if the link is pointing to a file or to a directory. By including the slash the browser instantly knows that the URL is pointing to a directory and doesn't need to spend any time trying to work it out. About the AuthorThis article was written by Trenton Moss. He's crazy about web usability and accessibility - so crazy that he went and started his own web usability and accessibility consultancy to help make the Internet a better place for everyone. |
||