Click to See Complete Forum and Search --> : Can use <link> to link two HTML files?


etrader_x11
10-19-2004, 05:45 PM
Hi everyone! I am building a site that has the same header on every page. I wonder if I can put that header in a separate HTML file and have all my pages linked to this file, so they don't have to reload the header everytime a customer opens a page. I was trying to use the <LINK> tag, but it seems to link only CSS or JavaScript files. How can I link two or more HTML files together? Thank you.

Jona
10-19-2004, 06:00 PM
You must use SSI (server-side includes) of some sort; whether through the standard SSI syntax or through a CGI (Perl, PHP, ASP, JSP, ColdFusion, etc.). The LINK tag is incapable of doing this.

etrader_x11
10-19-2004, 06:04 PM
I was trying to escape from doing SSI because the header file size isn't small. SSI will cause the browser to reload the header for every page, but I was trying to put that file into the browser's cash. Does anyone know if there is a better solution to this? Thank you.

Jona
10-19-2004, 06:06 PM
How could a header file be that big? There's no way to cache it because it's not a seperate file; the browser must have those headers in order for the page to actually work properly. They can be made seperate files, but in the end when you use includes from the server, the output is the same as if you had done each statically; the only difference is you save file space (not bandwidth).

etrader_x11
10-19-2004, 06:16 PM
I have a header file that had several .js and css ans Flash files linked to it files linked to it..From what I understand, when you use <link> it loads all those linked files into the browsers cash, so when you click on a different page, that is linked to the same file, the browser will reload all those resources from the memory, as opposed to loading it from the server.

Jona
10-19-2004, 06:20 PM
The link element does not display information, it specifies where the user agent can request different information from; e.g., a different URI for an alternate language of the text, or the next page of a manual. You cannot include header files using this tag, because it is to tell the user agent where a linked resource is and how to get to it; it does not command the user agent to pull data from another resource on the current page unless it is a stylesheet.

etrader_x11
10-19-2004, 06:26 PM
I thought <link> actually pulls the data from a resource and saves it in the memory. For example, if the resource is a .js file, will you not need all the speed you can get from having your browser execute all the JavaScript commands from the memory as opposed to sending those commands to the server?

Jona
10-19-2004, 06:32 PM
The LINK element (http://www.w3.org/TR/html4/struct/links.html#h-12.3) was not created for any ECMAScript (such as JavaScript); if you specify the content type, source location, and purpose of an external JavaScript through the LINK tag, the browser only knows what URI to forward to in order to get that information if it is requested. It does not know that the functions on that page refer to the code located inside of that which was linked to by the LINK element itself. Therefore, the LINK element is only to point to a relative resource for the document being viewed, and not to download data into cache. Stylesheets are automatically downloaded because of their detected type for the document, because that is what the HTML 4.01 specification requires it to do; however, it does not even mention ECMAScript or any other documents, and none of these documents (with the exception of CSS) are cached.

Stephen Philbin
10-19-2004, 06:39 PM
I'm on a whistle stop tour here to excuse my brevity, but consider the following article carefully.

http://www.w3.org/QA/Tips/use-links

etrader_x11
10-19-2004, 06:42 PM
I think W3C should've provided an attribute to the <link> tag to allow the developer to decide, wether he wants the resource to be linked externally or to inlclude that resource into the cash. Something like:

<link href="..." cash="yes" >

Jona
10-19-2004, 06:45 PM
Originally posted by etrader_x11
I think W3C should've provided an attribute to the <link> tag to allow the developer to decide, wether he wants the resource to be linked externally or to inlclude that resource into the cash. Something like:

<link href="..." cash="yes" >

It's spelled cache. Anyway, you can specify whether to cache documents or not -- just resent the header information. Usually this request is best sent by the server, but you can send it as HTML and the user agent will usually understand not to cache the document; however, I don't believe this applies to everything located in the page, such as images, stylesheets, or external JavaScript files. Still, the bottom line is there is no way to include headers on every page without using server-side includes.

etrader_x11
10-19-2004, 06:50 PM
Thanks everyone.
(excuse my English ):)

Jona
10-19-2004, 06:53 PM
Glad to help. :)