DN-01: Frontend Notes
Drive-by frontend notes, part one.
published Mar 17, 2017 tags
#javascript
#frontend
#notes
~/posts/dn-01 $ cat post.md
The DN series — drive-by things worth jotting down, mostly web-related.
Cookie limits
In IE, each domain has a cap on total cookies:
- IE6 and earlier: up to 20.
- IE7 and later: up to 50.
- Firefox: up to 50.
- Chrome and Safari: no hard cap.
IE and Opera also clean up unused cookies on a schedule; Firefox does
it randomly. By contrast, userData — supported on basically every
browser — doesn’t get wiped, with a per-entry cap of 128 KB.
Cookie upsides
Over SSL, cookies are hard to intercept; even if they are, a reasonable expiry keeps their value low. For cookies that don’t hold sensitive data, they’re a convenient transport.
display:none vs visibility:hidden
display:none: hides the element and removes its space in layout. Surrounding elements collapse together, as if it didn’t exist.visibility:hidden: hides the element but its space in layout is preserved.
link vs @import
<link>is an HTML tag;@importis a CSS rule.<link>loads in parallel with the page; CSS referenced by@importonly starts loading after the page is loaded.@importonly works in IE5+;<link>works everywhere.- Styles from
<link>have higher specificity than@import.
position:absolute vs float
- In common: applying
floatorposition:absoluteto an inline element takes it out of flow, and lets you give it explicit width and height. - Different:
floatstill occupies space and affects layout of other elements;position:absoluteis fully out of flow and can overlap other elements.
CSS selectors
- ID (
#my-id) - Class (
.my-class-name) - Tag (
div,h1,p) - Adjacent sibling (
h1 + p) - Child (
ul > li) - Descendant (
li a) - Universal (
*) - Attribute (
a[rel="external"]) - Pseudo-class (
a:hover,li:nth-child)
CSS3 pseudo-classes
p:first-of-type: the first<p>among its parent’s children.p:last-of-type: the last<p>.p:only-of-type: the only<p>among its parent’s children.p:only-child: a<p>that’s the only child of its parent.p:nth-child(2): the second child of its parent, when that child happens to be a<p>.:enabled/:disabled: form-control enabled state.:checked: radio or checkbox selected.
XML vs JSON
- JSON is smaller on the wire than XML, so it’s faster to transmit.
- JSON interoperates natively with JavaScript — easier to parse and handle.
- JSON is less descriptive than XML.
- Parsing JSON is much faster than parsing XML.
Doctype
<!DOCTYPE>can declare three DTD types — Strict, Transitional, and Frameset.- HTML 4.01 defines all three.
- XHTML 1.0 likewise defines three XML document types: Strict, Transitional, Frameset.
- Standards mode (strict) renders pages that follow current standards. Quirks mode (loose / compatibility) renders pages designed for older browsers.
HTML vs XHTML
- All tags must be closed.
- Element and attribute names must be lowercase.
- All tags must be properly nested.
- All attribute values must be quoted.
- Special characters like
<must be entity-encoded. - All attributes must have a value.
--is not allowed inside a comment.- Images must have alt text.