Imagining CSS for URLs and HTTP Headers
blog.jim-nielsen.com
blog.jim-nielsen.com
There... shouldn't be? I'm kind of missing the part that explains why you'd need this? Are there any concrete examples where "I need the headers and/or URL" lets you do something that you can't already do by making sure your document has the information it needs, in the document itself? (if you need URL-specific CSS, you just... load more CSS...? You template in the necessary <link> elements because your server knows which URL is being requested?)
I think the second linked article required an "edge function" to add the data- attribute to the HTML delivered to the client, and I think TFA's author doesn't like the need for that (i.e., wants to deliver a static document), but I think you could do it with some synchronous Javascript; the fallback for clients not wanting JS would be CSS media queries that just obeyed the UA's preferences… which seems like exactly what one should want…?
(So, I'm also missing a convincing "why", here.)
I don't think it completely solves it, but it would be useful to be able to apply styling to a specific part of the page ie: highlight something so when you send it, it saves the receiver a little time searching for it.
Or in a similar vein, wouldn't it be cool to make any header an anchor? So I could say,
http://example.com/article.html#second_header
or whatever. Not the same concept, but it would be useful.
Gemini clients still keep that dream alive, although there's plenty of disagreement as to exactly how it should function: https://gitlab.com/gemini-specification/gemini-text/-/issues...
You already can make any header an anchor, right?
eg: <h2 id="second_header">Second Header</h2>
I would already call this bit into question. At least originally, the "document" was only the HTML part. The task of HTTP was to shuffle the document around, not itself be part of the document.
In practice today, most documents have a HTTP request attached to it, but you can still see the issues if you try to load HTML from a file or from cache. What is the corresponding HTTP request for that?
I sort of can see the appeal of styling by URL, but that too seems in danger if opening a huge can of worms. Suddenly, you can't test styles locally anymore, because the domain name now influences the selectors. Also, if you move domains and forget to update your styles, suddenly your site will be broken.
> Setting aside the open-ended possibilities people might dream up with non-standard X- headers
What possibilities would that enable that couldn't also be done using data-* attributes?
> imagine being able declare some styles based on the presence of a cookie
Ok, that might be a useful idea after all.
#/etc/nginx/sites-enabled/whatever.conf
location /this-isnt-for-you.html {
add_header Link "<//site.com/isntforyouheader.css>; REL=stylesheet";
}
$ curl -I http://site.com/this-isnt-for-you.html
curl -I site.com
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 28 Nov 2022 18:08:01 GMT
Content-Type: text/html
Connection: keep-alive
Link: <//site.com/isntforyouheader.css>; REL=stylesheet
...
This works to set CSS atributes only for a specific URL on my static websites using .html files. For nginx. But nginx is a very common and secure choice for static sites and available in everyone's repos. And you can probably add arbitrary headers per path with other static webservers configs too.In the end the best solution is probably move this to the edge with includes and edge functions, with a non-tracking cookie or header.