04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

At Caffeine Buzz we use relative<br />

links to other pages on our site,<br />

and URLs to link offsite, like<br />

www.caffeineanonymous.com.<br />

there are no<br />

Dumb Questions<br />

Q: It seems like there are two ways<br />

to link to pages now: relative paths and<br />

URLs.<br />

A: Well, relative paths can only be<br />

used to link to pages <strong>with</strong>in the same Web<br />

site, while URLs are typically used to link<br />

to other Web sites.<br />

Q: Wouldn’t it be easier if I just<br />

stuck <strong>with</strong> URLs for links to my own<br />

pages and outside pages? That would<br />

work wouldn’t it?<br />

A: Sure, it would work, but there’s<br />

a couple of reasons you don’t want to go<br />

there. One problem is that URLs are hard<br />

to manage when you have a lot of them in<br />

a Web page: they’re long, difficult to edit,<br />

and they make <strong>HTML</strong> more difficult to read<br />

(for you, the page author).<br />

Also, if you have a site <strong>with</strong> nothing but<br />

URLs that link to local pages and you<br />

move the site or change its name, you<br />

have to go change all those URLs to<br />

reflect the new location. If you use relative<br />

paths, as long as your pages stay in the<br />

same set of folders – because the links<br />

are all relative – you don’t have to make<br />

any changes to your element href<br />

attributes.<br />

So, use relative links to link to your own<br />

pages in the same site, and URLs to link<br />

to pages at other sites.<br />

Q: Haven’t we seen one other<br />

protocol? I kept seeing “file://” before<br />

we started using a Web server.<br />

A: Yes; good catch. The file protocol<br />

is used when the browser is reading files<br />

right off your computer. The file URL,<br />

getting connected<br />

for example, “file:///chapter4/starbuzz/<br />

index.html”, tells the browser that the<br />

file “index.html” is located at the path<br />

“/chapter4/starbuzz/”. This path may look<br />

different depending on your operating<br />

system.<br />

One important thing to notice in case you<br />

try to type in a file URL is that the file URL<br />

has three slashes, not two, like HTTP.<br />

Remember it this way: if you take an HTTP<br />

URL and delete the Web site name you’ll<br />

have three slashes, too.<br />

Q: Are there other protocols?<br />

A: Yes, many browsers can support<br />

retrieval of pages <strong>with</strong> the FTP protocol,<br />

and there is a mail protocol that can send<br />

data via email. HTTP is the protocol you’ll<br />

be using most of the time.<br />

Q: I’ve seen URLs that look like<br />

this: http://www.mydomain.com:8000/<br />

index.html. Why is there a “:8000” in<br />

there?<br />

A: The “:8000” is an optional “port”<br />

that you can put in an HTTP URL. Think<br />

of a port like this: the Web site name is<br />

like an address, and the port is like a<br />

mailbox number at an address (say, in an<br />

apartment complex). Normally everything<br />

on the Web is delivered to a default port<br />

(which is 80), but sometimes Web servers<br />

are configured to receive requests at a<br />

different port (like 8000). You’ll most likely<br />

see this on test servers. Regular Web<br />

servers almost always accept requests<br />

on port 80. If you don’t specify a port, it<br />

defaults to 80.<br />

you are here 147

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!