TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Imagining CSS for URLs and HTTP Headers

31 点作者 5amdotis超过 2 年前

8 条评论

TheRealPomax超过 2 年前
&gt; there can be information critical to styling a webpage that lives outside of the HTML alone<p>There... shouldn&#x27;t be? I&#x27;m kind of missing the part that explains <i>why</i> you&#x27;d need this? Are there any concrete examples where &quot;I need the headers and&#x2F;or URL&quot; lets you do something that you can&#x27;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 &lt;link&gt; elements because your server knows which URL is being requested?)
评论 #33777432 未加载
评论 #33777258 未加载
评论 #33777207 未加载
评论 #33784109 未加载
xg15超过 2 年前
&gt; <i>How do we get the DOM? The browser knows how to create it from an HTTP request consisting of a URL, some headers, and some HTML.</i><p>I would already call this bit into question. At least originally, the &quot;document&quot; was <i>only</i> the HTML part. The task of HTTP was to shuffle the document around, not itself be part of the document.<p>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?<p>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&#x27;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.<p>&gt; <i>Setting aside the open-ended possibilities people might dream up with non-standard X- headers</i><p>What possibilities would that enable that couldn&#x27;t also be done using data-* attributes?<p>&gt; <i>imagine being able declare some styles based on the presence of a cookie</i><p>Ok, that might be a useful idea after all.
zffr超过 2 年前
You can simulate this today by having your webserver add HTML attributes for the HTTP headers, domain, path, etc to the body element. It should then be possible to write CSS selectors like the one in the article
评论 #33776739 未加载
Phelinofist超过 2 年前
Maybe I&#x27;m missing something but the proposed @document rule just mimics using different .css files for different pages? For example: about.css and then include that in the HTML of the about page?
评论 #33780696 未加载
ignitionmonkey超过 2 年前
The @document and other at-rules mentioned in the article are related to user styles. <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stylish" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stylish</a> was popular back in the days. As more and more websites moved towards generated CSS classes, it&#x27;s become more difficult to maintain custom styles.
Minor49er超过 2 年前
This would be a little more complicated to test with local static HTML files versus the same files being hosted on a server
luckylion超过 2 年前
Set-Cookie would only exist on the first requests where the server actually tells the client to set a cookie. On subsequent requests, the client would inform the server about the cookie (using the Cookie header), so this would have to match both requests and response headers.
tanepiper超过 2 年前
We have this exact problem currently solved with a little hack that uses sessionStorage and media qieries, but it&#x27;s an annoying.<p>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.