Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

10 new ways to speed up download time

Rated 3.76 (Ratings: 18) (Add your rating)

Log in to add a comment
(33 comments so far)

Want more?

 
Picture of trenton

Trenton Moss

Member info | Full bio

User since: March 04, 2004

Last login: November 27, 2005

Articles written: 4

1. Avoid tables for layout

Here are six reasons why pages that use CSS for layout download faster than tabular pages:

  • Browsers read through tables twice before downloading them, once to work out its structure and once to determine its content
  • Tables appear on the screen all in one go - no part of the table will appear until the entire table is downloaded and rendered
  • Tables encourage the use of spacer images to aid with positioning
  • CSS generally requires less code than cumbersome tables
  • All code to do with the layout can be placed in an external CSS document, which will be called up just once and then cached on the user's computer; table layout, stored in each HTML document, must be loaded up each time a new page downloads
  • With CSS you can control the order items download on to the screen - make the content appear before slow-loading images and your site users will definitely appreciate it

2. Don't use images to display text

It'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

a:link.example, a:visited.example, a:active.example  {
color:#fff; 
background:#f90; 
font-size:1.2em; 
font-weight:bold; 
text-decoration:none; 
padding:0.2em; 
border:4px #00f outset
}
a:hover.example {
color:#fff; 
background:#fa1; 
font-size:1.2em; 
font-weight:bold; 
text-decoration:none; 
padding:0.2em; 
border:4px #00f inset

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 CSS

It'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:

<div class="pretty-image"></div>

And this CSS:

.pretty-image { background: url(filename.gif); width: 200px; height: 100px }

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 selectors

This is inefficient:

<p class="text">This is a sentence</p>
<p class="text">This is another sentence</p>
<p class="text">This is yet another sentence</p>
<p class="text">This is one more sentence</p>

.text { color: #03c; font-size:2em }

Instead of assigning a value to each individual paragraph, we can nest them within a &#60;div&#62; tag and assign a value to this tag:

<div class="text">
<p>This is a sentence</p>
<p>This is another sentence</p>
<p>This is yet another sentence</p>
<p>This is one more sentence</p>
</div>

.text p { color: #03c; font-size:2em }

This second CSS example basically says that every paragraph within class=&quot;text&quot; should be assigned a colour value of #03c and a font size of 2em.

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 properties

Font

Use:

font: 1em/1.5em bold italic serif

...instead of

font-size: 1em;
line-height: 1.5em;
font-weight: bold;
font-style: italic;
font-family: serif

Border

Use:

border: 1px black solid

...instead of

border-width: 1px;
border-color: black;
border-style: solid

Background

Use:

background: #fff url(image.gif) no-repeat top left

...instead of

background-color: #fff;
background-image: url(image.gif);
background-repeat: no-repeat;
background-position: top left;

Margin, padding, border

Use:

margin: 2px 1px 3px 4px
(top, right, bottom, left)

...instead of

margin-top: 2px
margin-right: 1px;
margin-bottom: 3px;
margin-right: 4px

Use:

margin: 5em 1em 3em
(top, left and right, bottom)

...instead of

margin-top: 5em;
margin-bottom: 1em;
margin-right: 1em;
margin-right: 4em

Use:

margin: 5% 1% (top and bottom, left and right)

...instead of

margin-top: 5%;
margin-bottom: 5%;
margin-right: 1%;
margin-right: 1%

These rules can be applied to margin, border and padding.

6. Minimise white space, line breaks and comment tags

Every 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-ups

Never 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: &#60;a href=&quot;http:&#47;&#47;www.URL.com&#47;filename.htm&quot;&#62;. Much better would be &#60;a href=&quot;filename.htm&quot;&#62;. But what if some files are in different folders to other ones? Use absolute or relative linking:

  • &#60;a href=&quot;&#47;&quot;&#62; - Calls up http://www.URL.com
  • &#60;a href=&quot;&#47;filename.html&quot;&#62; - Calls up http://www.URL.com/filename.html
  • &#60;a href=&quot;&#47;directory&#47;filename.html&quot;&#62; - Calls up http://www.URL.com/directory/filename.html
  • &#60;a href=&quot;.&#47;&quot;&#62; - Calls up index.html within that directory
  • &#60;a href=&quot;..&#47;&quot;&#62; - Calls up index.html one directory above
  • &#60;a href=&quot;..&#47;filename.html&quot;&#62; - Calls up filename.html one directory above
  • &#60;a href=&quot;..&#47;..&#47;&quot;&#62; - Calls up index.html two directories above

8. Remove unnecessary META tags and META content

Most 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 documents

We all know to do this, yet we so often don't do it!

To place CSS in an external document use:

&#60;link type=&quot;text&#47;css&quot; rel=&quot;stylesheet&quot; href=&quot;filename.css&quot; &#47;&#62;

To place JavaScript in an external document use:

&#60;script language=&quot;JavaScript&quot; src=&quot;filename.js&quot; type=&quot;text&#47;javascript&quot;&#62;&#60;&#47;script&#62;

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 links

Don't do this: &#60;a href=&quot;http://www.URL.com&#47;directoryname&quot;&#62;

Do this instead: &#60;a href=&quot;http://www.URL.com&#47;directoryname&#47;&quot;&#62;

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.

Trenton Moss is crazy about web usability and accessibility - so crazy that he set up his own usability and accessibility consultancy (Webcredible). He's extremely good at usability training and web writing training.

eh?

Submitted by r937 on March 6, 2004 - 07:14.

"Never use an absolute call up as it ... takes the browser longer to download the page"

explanation please?

login or register to post comments

Re: Put CSS and JavaScript into external documents

Submitted by fluoronaut on March 8, 2004 - 01:17.

Hmm, I was under the impression that (depending on the web server), using external documents could seriously damage your download time because of the extra time taken to render the page from numerous files rather than just one. I imagine this is dependant on the size of the file that's being included and that in some cases it can improve the download time. But I wouldn't recommend a blanket use of external files in every single case.

login or register to post comments

Comments

Submitted by Martin Tsachev on March 8, 2004 - 01:30.

"5. Use shorthand CSS properties"
I'd rather use the full form if I'm not sure about something or need to make it easier to read.

"Never use an absolute call up as it ... takes the browser longer to download the page"
It doesn't take much longer to download the page but it definitely makes the site harder to maintain and test with a local/dev copy.

"10. Use / at the end of directory links"
Browsers are not actually that smart to start figuring out such things, but it takes an additional request/response from the server to redirect the browser to the dir/ URL.

login or register to post comments

11, 12 and 13...

Submitted by Hotel on March 8, 2004 - 04:43.

11) I know that it is hard... but try to create a CSS not bigger than 1160 bites, so it can be sent in one only TCP/IP high speed packet! :) 12) Minimizing HTTP requests, AKA do not load too many files at the same times (like 20 images), so most browsers can multithread 13) use HTTP compression with mod_gzip or similar products. (I haven't tried this one yet)

login or register to post comments

jenson

Submitted by lemoncurry on March 8, 2004 - 06:15.

hmn.. this is a little weak, to say replacing a class="text" with a smarter css rule will knock 20% is far fetched... if u designed ur stylesheet more intelligently it wouldn't need class="text" on every P!!!!! too generalised.... the fact is most people can grasp classes, rules, and matching tags. What is neglected by most sites, are the advanced cascading concepts of css, eg. inheritance and what is and what is not explicitly supported by a browser. Similarly with JS, how to build intelligent adv objects is neglected and to some extent the modular ideas encompassed by xhtml1.1 if the site is built from several sources (xml, data) this will be quicker to assemble as one flat file... but that can only then be cached as a final page, id seriously consider whats happening on the actual server.... External files are better when universal across the site, its a far more important point: use css instead of spacers and images! no more small design elements.... secondly just use an editor with the carriage return character turned on, it makes worrying about whitespace easy, and u can ensure it uses as least as possible whilst writing it... saves more time...

login or register to post comments

Great article

Submitted by paulnattress on March 8, 2004 - 08:50.

Great article Trenton. Advice like this (including all of the comments) is the sort of practical advice that is sadly missing from most web design teachings.

login or register to post comments

Browsers reading before downloading?!

Submitted by asjo on March 8, 2004 - 10:26.

"Browsers read through tables twice before downloading them, once to work out its structure and once to determine its content"

How do browsers read through a table, even once, *before* downloading it?

login or register to post comments

Good article, but there's room for inprovement!

Submitted by ras on March 8, 2004 - 13:49.

Got inspired and took a look at my web site. This is what I started with:

.bannerText A {
COLOR: white; TEXT-DECORATION: none;
}
.bannerText A:active {
COLOR: white; TEXT-DECORATION: none;
}
.bannerText A:hover {
COLOR: white; TEXT-DECORATION: none;
}
.bannerText A:visited {
COLOR: white; TEXT-DECORATION: none;
}

And this is how it ended up looking:

.bannerText A,
.bannerText A:active,
.bannerText A:hover,
.bannerText A:visited { COLOR: white; TEXT-DECORATION: none; }

Much easier to read and shortened the stylesheet considerably. Also it is possible to declare this class in the TD field in stead of in the actual link, thus saving a lot of extra typing, when you can apply it to x amount of links with one line.

login or register to post comments

hmmm

Submitted by flump on March 9, 2004 - 11:23.

@ras: that code could be improved more. .bannerText a { COLOR: #FFF; TEXT-DECORATION: none; } will do what you want. also it doesnt take longer to download pages like http://mysite.com/mypage.htm the browser has to convert all your page links to this format before requesting each page/file anyway.

login or register to post comments

hmmmm, but....

Submitted by ras on March 9, 2004 - 16:40.

@flump: You're right, if I didn't have a general A { COLOR: #000066; TEXT-DECORATION: underline; } ruining it all for me... Otherwise you're spot on!

login or register to post comments

Absolute vs relative URLs

Submitted by RichardM on March 11, 2004 - 05:39.

"Never use an absolute call up as it takes up more space, and more importantly, takes the browser longer to download the page."

I'm pretty sure that's wrong.
Every GET request to a webserver would pretty much look like this in the server logs wether the URLs are relative or absolute:
www.evolt.org - - [11/Mar/2004:13:40:18 -0000] "GET /index.html HTTP/1.1" 200 6306

As far as I can see, it wouldn't take the browser any longer (or shorter) to download the file because the request would always be the same, unless it uses some kind of persistent connection to the server.

login or register to post comments

Re: Absolute vs relative URLs

Submitted by joek on March 11, 2004 - 06:59.

"As far as I can see, it wouldn't take the browser any longer (or shorter) to download the file because the request would always be the same"

Acutally, I think the issue might be about filesize. "http://www.domain.com/filename.html" uses more characters than just "filename.html". In similar advice is to use shortened directory names for common elements, like "s" instead of "styles" or "i" instead of "images", because those small savings of a few characters can add up on larger pages.

login or register to post comments

Two notes

Submitted by notabene on March 15, 2004 - 10:28.

"Tables appear on the screen all in one go - no part of the table will appear until the entire table is downloaded and rendered"

That's not true anymore. It was, back in Netscape 4 days. But not anymore. Mozilla for instance displays table cells as soon as it has read their content. Then it most often has to re-lay out the page, since basically there won't be only one cell per row.

Also:

To place JavaScript in an external document use:
&lt;script language="JavaScript" src="filename.js" type="text/javascript"&gt;&lt;/script&gt;

Please keep in mind that language="JavaScript" implicitly says that the browser can consider the script as Javascript 1.0 or any superior version. Most often, one tends to test every method/property before using it, thus JS versioning (1.0, 1.1, 1.2 etc) tends to become obsolete, and the language attribute has been declared deprecated in HTML 4.01.

login or register to post comments

cmts

Submitted by mrnbk on March 16, 2004 - 12:26.

Hi.

1. Avoid tables for layout

"CSS generally requires less code than cumbersome tables"

Less code != better code

3. Call up images through CSS

Nonsense. Browsers usually use placeholders for big images.

4. Use contextual selectors

"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."

You can, but you should not use those.

10. Use / at the end of directory links

True, but the *problem* is on the server side:

http://www.URL.com/directoryname -> 2 HTTP requests
http://www.URL.com/directoryname/ -> 1 HTTP request

$ telnet www.evolt.org 80
Trying 207.189.150.139...
Connected to www.evolt.org (207.189.150.139).
Escape character is '^]'.
GET /evolt HTTP/1.0
Host: www.evolt.org

HTTP/1.1 302 Object Moved
Location: http://www.evolt.org/evolt/
Server: Microsoft-IIS/5.0
Content-Type: text/html
Content-Length: 150
Connection: Close

Document Moved
Object MovedThis document may be found hereConnection closed by foreign host.


@899, Nbk

login or register to post comments

mrnbk, why shouldn't we use CSS shorthand?

Submitted by dotcomikaze on March 18, 2004 - 03:47.

4. Use contextual selectors

"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."

You can, but you should not use those.


Why not?

login or register to post comments

Why Not?

Submitted by mrnbk on March 18, 2004 - 21:48.

Hi.

Because you should "Keep It Simple". You can't find "#03C" searching for "#0033CC". The "next guy" will thank you for that.

@291, Nbk

login or register to post comments

Regarding Why Not....

Submitted by dotcomikaze on March 19, 2004 - 05:32.

Understood but I was thinking maybe there was some technical reason why I shouldn't. I tend to use shorthand as much as possible and I have been doing it long enough that I think it is simpler than writing out the entire color(yes I know it is only 3 letters).

If I am the only guy who understands the shorthand at my place of employment, maybe they won't find 'a next guy' to replace me ;)

Thanks,
.comikaze

login or register to post comments

3. Call up images through CSS

Submitted by pab29 on April 2, 2004 - 09:51.

3. Call up images through CSS Its very useful solution. I will test it my pages now. Thank you.

login or register to post comments

Calling images via CSS

Submitted by nainil on April 5, 2004 - 14:33.

Hi,

Web site visitors hate to wait, so many Web designers preload images to speed up page display. Although JavaScript is the most common way to preload images, it isn't your only option. Consider using the CSS DISPLAY property instead. It may be more reliable and it requires less complex code.

The article below shows it all
http://www.netmechanic.com/news/vol6/css_no18.htm

login or register to post comments

A few corrections.

Submitted by haidary on April 20, 2004 - 22:10.

First, the way you're calling up images with CSS is actually bad. Why? I don't see any way to give that image alt text do you? It also requires you to use extraneous markup (the div). Only use images in style sheets if they're part of the site style, not if they're related to the content.

Second (@ nainil), the display property shouldn't help you preload anything as the W3C defines it to completely supress rendering of an element and its contents. If the element isn't rendered than it wouldn't make sense if the image was loaded anyway. If it gets loaded in a browser while it's displayed as none it's a bug (even if the vendor doesn't consider it one).

login or register to post comments

Shorthand speeds up download time?

Submitted by DanteCubed on May 8, 2004 - 22:28.

I would think that the download time saved by using shorthand CSS properties would be a drop in the ocean: like milliseconds (or nanoseconds).

login or register to post comments

Shorthand speeds up download time.

Submitted by joek on May 11, 2004 - 03:03.

DanteCubed:
I would think that the download time saved by using shorthand CSS properties would be a drop in the ocean: like milliseconds (or nanoseconds).
"One raindrop raises the sea."

Think of it this way: FC0 is 50% smaller than FFCC00. Sure, in the larger scope of your whole CSS file, it may only be a little, but in the long run (as your CSS file grows), a little can add up.

Or think of it another way... do you save pennies? Why? Because eventually they'll add up.

login or register to post comments

tables for layout? eewwww

Submitted by r937 on May 11, 2004 - 03:45.

ooh, sneaky, a link to your site in a period!! that's good web design!!

login or register to post comments

Tables for Layout and Periods for Links

Submitted by freewanderer on May 16, 2004 - 01:53.

Jain, How about using CSS-P for layout? There are plenty of workarounds available to make CSS positioning work in modern browsers ( IE 5+, NN5+, Mozilla etc.). It's high time to move on to standards-based designing.

login or register to post comments

In sincerely hope you're kidding...

Submitted by DanteCubed on May 17, 2004 - 16:40.

...about nested tables for layout.

"If possible, try to break Web pages into several small tables."

Also, if possible, break your car engine into several small parts. Then see how well it runs.

If you can't tell I was being sarcastic. If Rahul is silly enough to use tables for layout, he may not be smart enough to recognize sarcasm.

login or register to post comments

Dante: warning, slippery tone

Submitted by notabene on May 18, 2004 - 05:18.

Dante,

I'm sorry to point it out, but please refrain from saying people are 'silly', 'not smart enough', etc. That's the tone you used on a few of your comments on ALA, and then you came back to us content members complaining that people didn't like you and flamed you. This community is about helping each other, not starting flame wars.

Remember that:

  1. Your mileage may vary. Some people are beginners, some are old wolves of the web.
  2. You can say someone is mistaken, but please provide grounds on which you base your judgment. Value judgments are not very acceptable.
  3. Even if someone is mistaken (it happens to all of us sometimes, doesn't it), it does not give you the right to flame them with expletives.
  4. Some people are not natives in english. I'm French, Rahul is Indian, etc. Please respect differences.

You know that I never post a comment before re-reading it at least twice. I don't want to hurt any sensibility. Thank you for respecting that in the future, Dante.

login or register to post comments

glossing over tables

Submitted by drax on May 20, 2004 - 09:22.

This article is great, however formating tables in css is somthig that is mentioned in alot of places but there do not seem to be any guides to learning how to implement them. any ideas where a guy might find this kind of info. I do try to use css at my site local portal for thunder bay, ontario, canada but using css for tables is somthing that escapes me.

login or register to post comments

Re: tone

Submitted by DanteCubed on May 20, 2004 - 18:31.

"I'm sorry to point it out, but please refrain from saying people are 'silly', 'not smart enough', etc"

Duly noted, although your tone sounds a bit condescending.

Good to see another French person, though I was not born there.

I thought Rahul was being sarcasting, to be honest.

login or register to post comments

From Tables to CSS

Submitted by freewanderer on May 20, 2004 - 20:38.

Drax, There are plenty of resources out there on the web explaining the art of CSS-P, which will help you get rid of all the messy tables. Some nice tutorials for CSS are housed at css.maxdesign.com.au. CSS Positioning can be found at www.positioniseverything.net. All the best CSS related stuff tend to appear at www.alistapart.com. I'll come up with some more places soon.

login or register to post comments

Love Tables

Submitted by mantik on June 6, 2004 - 02:54.

I love to use nested tables. They are just so handy for laying out xml pages. But I know that they can be a problem, so I try to make sure that they're really necessary to my design. Almost worse than nested tables are entire Web pages enclosed in one table. Your page won't appear until the entire table has been written by the browser. If possible, try to break Web pages into several small tables.

login or register to post comments

Broken Record on Tables?

Submitted by freewanderer on June 6, 2004 - 20:57.

Hey Mantik,
Are you a ghost of Jainrahul or what?
XML is better off with something modern, so how about dumping those rusty old tables and going for CSS or XSLT+CSS ?
Your XML deserves better treatment than tables.

login or register to post comments

How it look vs what it is

Submitted by Alfatrion on November 24, 2004 - 08:51.

4. Use contextual selectors I feel that CSS should be used to discribe how it should look and HTML for what it is. I think this advise loses the focus on this resuling in effects in the layout at some time. At a later date you could add a option like 'margin-bottom: 16px'. This will have a diffent effect than if you didn't use the tags to discribe what it is.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.