=============================================================================== notryan.com/blog/013.txt Fri, 08 May 2020 Ryan Jacobs 14:54:20 -0700 Fun Facts on Producing Minimal HTML . . . . . . . . . . . . . . . . . . =============================================================================== This article is about HTML5. Note: Some of these *might* break spec, but are so commonplace that they might as well be in here. For example,
is required by the HTML spec, but 99% of all browsers will make up something for you if it isn't supplied. Note: I wouldn't use this advice on production websites. But for quick development, here are some tips that help me. ------------------------------------------------------------------------------- Here we go: * Text outside of tags is acceptable in modern browsers. * *is* required by the HTML spec (but not the XHTML spec). 99% of browsers will not care if you omit it. It was created for backwards compatibility with prior HTML versions. You can omit it for minimal HTML5 documents. * , , are not required by modern browsers. Your document will render fine without them. You don't need to wrap your document with and . * You don't need to close your tags. For example, create a document, add, add some content, and then end the document without providing the closing
tag. The browser will construct a DOM with a element. Closing tags will be generated for you, in a nested fashion. This lets you to do things like this: (Although, meta redirects aren't even spec compliant with W3C... but alas, that's a can of worms for another day...) * Quotes are optional for tag parameters. For example, (Of course, there must be no spaces, etc.) * Both single-quotes and double-quotes are valid for tag parameters. This is useful for producing valid HTML output in programs without resorting to escaped double-quote. For example, in the C language: printf("Hi there!
\n"); * If you do not define , then most browsers will default to ASCII or Windows-1252. So if you are confidently in the ASCII range, skip the declaration. * Using a preformatted block () of links is a handy way to introduce automatic line breaks. For example, this will render nicely:
link 1 link 2 link 3
Though, keep your links short and be mindful that your text will not wrap. I like using this technique to generate stupid simple index.html files in BASH: #!/bin/bash gen() { echo "
" for f in *; do echo "$f" done echo "
" } gen | tee index.html This works with filenames containing spaces... but not single quotes. Modify it for your use cases. * Add this tag to support mobile views: This snippet is copy and pasted a whole lot around the web. Most people don't explain how it actually functions though. "width" sets the initial width to the mobile's physical display width in 100% pixels. This will ensure that the max-width property works properly. Tags such as
have an implicit `max-width: auto`. Now their content will flow properly and wrap to the display's dimensions. "initial-scale" sets the initial zoom to a more sensible value, so that high DPI screens (i.e. smart phones) will fill the screen properly. ------------------------------------------------------------------------------- Thanks for reading. Last of all, if you are currently reading on a mobile device, this website was served to you via server.c, which you can find at the root of this site. I detected your User-Agent as mobile and served you an HTML version of this text document to prevent text wrapping. The HTML document was produced as "Minimal HTML" by mobile.c, which you can also find at the root of this site. I apologize if 80-column text is hard to read on your phone. But I don't want to deal with two different versions of my site. I like plaintext. I like formatting it exactly how I want. You're seeing it like you would on the desktop.
from Hacker News https://ift.tt/3bislKH
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.