logoalt Hacker News

90s_devlast Saturday at 10:55 AM1 replyview on HN

Also you don't need to separate :root from html in your code, they're always the same here, so you can save a couple lines by joining them.


Replies

chrismorganlast Saturday at 1:57 PM

And if talking of such optimisations—

• Trailing slashes in HTML content (apart from SVG/MathML) are completely useless, unless you’re serving the document in XML syntax (which you can’t do by accident). I personally think they’re harmful, because they encourage an incorrect belief, and are seldom even applied consistently.

• <html>, <head>, </head>, <body>, </body> and <html> are all optional. In practice, you should have an <html lang> attribute so that you can’t omit that tag, but the others can normally all be omitted.

• In case-insensitive things, lowercase will normally compress better. But Brotli messes things up because it’s a popularity contest of the HTML that people actually write, so that <!DOCTYPE html> compresses better than <!doctype html>, and even <meta charset="utf-8"> compresses better than <meta charset=utf-8>. Anyway, <meta charset="UTF-8" /> would be better as <meta charset="utf-8">.

• In <meta name="viewport" content="width=device-width, initial-scale=1.0" />, the space after the comma, and the .0 in initial-scale, are unnecessary. (In fact, in theory the .0 might not even be parsed: the badly-incomplete-and-extremely-dodgy spec says to use strtod, which is locale-dependent, so a French machine might parse initial-scale=1.5 as only one, ignoring the .5 because it’s not ,5. In practice I’d be mildly surprised if browsers used the real locale-dependent strtod, though I haven’t checked. If some spec somewhere says “assume LC_ALL=C in such cases”, which would also largely resolve the problem, I’d like to know.)

All up (and with title fixed to be a proper placeholder, as discussed):

  <!DOCTYPE html>
  <html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>{{ title }}</title>
  <style>
      html {
          color-scheme: light dark;
          font-family: system-ui, sans-serif;
          max-width: 70ch;
          padding: 3em 1em;
          margin: auto;
          line-height: 1.5;
          font-size: 1.25em;
      }
  </style>

  <a href="/" id="head-link">Carl Öst Wilkens' Blog</a>
  {{ content }}
show 1 reply