Rob Eberhardt

cleverness ensues

skip navigation

 Thursday, October 20, 2005

Anne van Kesteren just posted about the Opera 9 Preview.  More notable to me is the testcase for Linking to style sheets with HTTP headers.

Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
 <head>
  <title>CSS: Linking to style sheets with HTTP headers</title>
  <meta name="Author" content="Krijn Hoetmer ~ http://ktk.xs4all.nl/">
 </head>
 <body>
  <h1>Linking to style sheets with <abbr title="HyperText Transfer Protocol">HTTP</abbr> headers</h1>

  <p>This line should (or could) be red.</p>
  <hr>
  <h2>Code</h2>
  <pre><code>Link: &lt;index.css&gt;; REL=&quot;stylesheet&quot;; MEDIA=&quot;screen&quot;</code></pre>
 </body>

</html>

The testcase already works (P element in red) in the current Firefox 1.07 (but not IE, natch).  Style code is utterly missing from the document -- there are no style attributes, and no <style> or <link> elements.

That's because they're not in the document.  It's in the headers of the HTTP response which delivered the document.  I had to find the style insertion with the Fiddler tool (a great IE addin), and this is what I found in the HTTP headers:

Link: <index.css>; REL="stylesheet"; MEDIA="screen"

I must've missed the memo where this became a standard (since multiple browsers now support it).  I miss how it's a good idea too...

Yes, there's a gee whiz factor to it.  I could even think of possible uses for HTTP style includes (like configuring includes at the website level via the web server, something which IIS already can do with normal include files). 

But it just seems like a bad idea.

Granted, the line between protocol and document was crossed long ago with HTTP-EQUIV META tags.  This, however, crosses it in the opposite direction, by putting not meta-data, not layout or behavior data, but style data into a transport protocol!

Now I'm no code purist -- I feel most like a "SAVD" on Molly's scale  (What's bizarre is that I'd consider Anne much closer to a purist, a "SASS" to Molly.) 

We have CSS to get the font tags out of HTML.  Why not cram it into something even more poorly suited like HTTP?!

VERY bad idea.

10/20/2005 3:51 PM Eastern Daylight Time  #    Disclaimer  |  Comments [6]  | 
8/23/2006 11:20:07 PM (Eastern Daylight Time, UTC-04:00)
&lt;blockquote&gt;I must've missed the memo where this became a standard&lt;/blockquote&gt;
<br>
<br>This method has been standardized when HTML 4 became a standard:
<br><a target="_new" href="http://www.w3.org/TR/html4/present/styles.html#h-14.6">http://www.w3.org/TR/html4/present/styles.html#h-14.6</a>
<br>
<br>Of course, this isn't something that you'll be using over a &lt;code&gt;LINK&lt;/code&gt; or a &lt;code&gt;STYLE&lt;/code&gt; element when you're making a web page, but in some cases, where <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a> is also involved, it can be quite useful. Like the example given in the last paragraph: email.
8/23/2006 11:20:07 PM (Eastern Daylight Time, UTC-04:00)
It's defined in [HTML4.01] 14.6 Linking to style sheets with <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a> headers and would have been in in <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a>/1.1 if not for lack of implementations at that time.
<br>
<br><a target="_new" href="http://www.w3.org/TR/REC-html40/present/styles.html#h-14.6">http://www.w3.org/TR/REC-html40/present/styles.html#h-14.6</a>
8/23/2006 11:20:07 PM (Eastern Daylight Time, UTC-04:00)
Thanks guys, I'd missed that previously. I guess I'm glad it IS part of a standard. That's better than implementing a NON-standard bad idea at least. :&gt;
<br>
<br>Internet and Web Dev techonologies are complicated enough on their own without mixing them. I say keep development code should out of the TCP/IP stack (HTTP being the Application layer).
<br>
<br>Besides the debugging pain it could create (even for a pro), this stuff is already complicated enough. Molly called it a &quot;snakepit&quot; (<a target="_new" href="http://www.molly.com/2005/10/18/web-design-and-development-personality-indicators/">http://www.molly.com/2005/10/18/web-design-and-development-personality-indicators/</a>) the other day, which is apt: I've used a dozen technologies on a project, and that's not counting the ones I know but CAN ignore. The interactions can be very complex.
<br>
<br>Worse, SOMEone's going to write a tutorial on how to do this, further confusing beginners who are still struggling with concepts like generating browser code with server-side code. Then I'll be answering much worse questions than &quot;why is my <a title="" href="" ><acronym title="Active Server Pages">ASP</acronym></a> code still giving errors when I've wrapped it in HTML comment tags?&quot;.
<br>
<br>WORST is the mess that the intermediate-skilled developers will generate with this. Yet another rope to hang themselves with, and future fodder for <a target="_new" href="http://thedailywtf.com/">http://thedailywtf.com/</a>.
<br>
8/23/2006 11:20:08 PM (Eastern Daylight Time, UTC-04:00)
BTW, linked styles in email (either normal or <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a>) is ALSO a bad idea, but for security reasons. It's yet another way to run &quot;web bugs&quot; (thus far accomplished with linked styles, scripts, images, IFRAMEs, etc), which are why many people only do plain text email these days. (I miss being able to count on bold, italic or the occasional color).
<br>
<br>Anyway, these are web browsers, not email clients.
8/23/2006 11:20:08 PM (Eastern Daylight Time, UTC-04:00)
I do not think it is a big mess, if implemented well on all browsers we have the possibility to seperate all links to a style(sheet) from the HTML or <a title="" href="" ><acronym title="eXtensible Markup Language">XML</acronym></a> document.
<br>
<br>The reason nobody knows about this is because Internet Explorer failed to implement this handy feature. I hope <a title="" href="" ><acronym title="Internet Explorer">IE</acronym></a> will support this too, because it is then possible to attach a stylesheet independant of the contents of the HTML (change a link to a stylesheet, eg use another file or add a file) with the addition of 1 line to .htaccess or the server configurations...
8/23/2006 11:20:08 PM (Eastern Daylight Time, UTC-04:00)
&quot;attach a stylesheet independant of the contents of the HTML with the addition of 1 line to .htaccess or the server configurations...&quot;
<br>
<br>I agree that that is a good idea. I've needed to do that often. It's the implementation I dislike. Debugging <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a> is a PITA.
<br>
<br>With <a title="" href="" ><acronym title="Internet Information Services">IIS</acronym></a> document footers, I can attach ANY code to a website's returned documents, not just a stylesheet link. Not sure if other web servers can do a similar trick.
<br>
<br>Mind you, I've found <a title="" href="" ><acronym title="Internet Information Services">IIS</acronym></a> document footers too inflexible for practical use. They're just the rough IDEA that I'd prefer implemented: a blanket, server-side way to add includes to the normal returned documents.
<br>
<br>If <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a> <a title="" href="" ><acronym title="Cascading Style Sheets">CSS</acronym></a> includes are a good idea, then aren't <a title="" href="" ><acronym title="HyperText Transport Protocol">HTTP</acronym></a> SCRIPT includes conspicuously absent?
<br>
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):