Xah Web Dev Blog

You, put $5 in my patreon. https://www.patreon.com/xahlee

Web DevTwitter me

Xah Web Dev Blog Archive

Modern JavaScript Explained For Dinosaurs

great article

[Modern JavaScript Explained For Dinosaurs By Peter Jang. At https://medium.com/the node js collection/modern javascript explained for dinosaurs f695e9747b70 ]

“modern” template driven html. prefetch all the ads in the world

modern template driven html prefetch ads 2018-12-10 5fd44
a typical “modern” template driven html. prefetch, prefetch, prefetch all the ads in the world

browser war, and mobile has passed desktop/laptop for browsing since ~2016.

mobile vs desktop xahleeinfo 2018-12-06 5ec91
mobile vs desktop xahleeinfo 2018-12-06 , 1 week

for my xahlee.info, mobile is only 25%, because most of xahlee.info is programing stuff.

If you design website, make sure it works well on phone screen.

web browsers market share 2009-2018 29c67
web browsers market share 2009-2018

browser war. Google Chrome is now king of abuse. Firefox and Microsoft Edge are irrelevant

Google force android phone to install Chrome. also, bundling chrome with chromebook. And make sites that works well in Chrome only.

Here's a great article.

[The State of Web Browsers By Ferdy Christant. At https://ferdychristant.com/the-state-of-web-browsers-f5a83a41c1cb ]

that guy's “been in the web game since 1996”. i began writing html in 1996 too.

See also: hackernews comment on Google Chrome abuse. https://news.ycombinator.com/item?id=18617189

npm Fiasco. Malware that Steals Bitcoin

am so enjoying npm's fiasco. a malware that steals bitcoin, obfuscated in event-stream package https://www.theregister.co.uk/2018/11/26/npm_repo_bitcoin_stealer/ i hear it's used by Angular, Vue, Bootstrap. Which means, all websites you visit use it! npm, its leader, is a power hungry skum, and most js coder r milen gen ignoramus

npm's leader, from the few incidents i've seen over the years, is a power hungry skum. and js coders tend to be milen gen eedeots that r pillar of the sjstuff in programing community. also, in js land, 5 lines of code is a package.

npm flatmap-stream malware 2018-11-27 6f6b3
npm flatmap-stream malware 2018-11-27 6f6b3 [https://npm-stat.com/charts.html?package=flatmap-stream&from=2018-09-05&to=2018-11-27]

the npm malware has been downloaded 8 million times

you wonder, why in JavaScript land 5 lines is a package? i haven't looked in depth, but i think:

apparently, this happened to python recently

SVG: Font Size

updated. Still haven't found a solution to something like css's 1rem, when user coordinate is used.

HTML Video Tag

HTML Audio Tag. updated.

Mac still doesn't support webm video nor opus audio

DOM: Disable Right Click

new page. a simple, frequently asked example.

How JavaScript Works Douglas Crockford 2018 fecaa
How JavaScript Works, 2018, by Douglas Crockford Buy at amazon

Douglas Crockford has a new book How JavaScript Works I thumbed thru in a friend's house. It's very good. It's unusual. It's not for beginners. And written in a stye you have to read from cover to cover in sequence. But you get deep understanding.

JavaScript SVG Clock

JS: SVG Clock updated code.

it's so convenient to use bleeding edge tech. .insertAdjacentElement DOM: .insertAdjacentElement and .currentScript DOM: Get Current Script Tag no more inserting an id and get element by id

Web Design: Fixed-Layout, Flowed-Layout, Responsive Design

Note that in 2000s, there is big brouhaha among “web design” circles about Fixed-Layout vs Flowed-Layout. Most sites is fixed layout. best example is Apple. They assume ur screen is ≥ 1000 pixels wide. Fixed layout is like printed magazine. if ur window is smaller, u can only see parts.

see Web Design: Fixed-Layout vs Flowed-Layout

here's minimal window width assumptions of apple facebook google microsoft amazon etc sites around 2010 see Web Design, Minimal Window Width

the debate about fixed vs flowed layout is that, fixed is always better looking on a specific screen. But flowed looks much better on a screen not the designer intended/expected.

I prefer flowed, and thought about it for years. Flow layout is supposed to work in any screen size and ratio. In practice, its just impossible. What actually happens, as with today's “responsive design”, is just design for four or so intended screen size and ratio.

note that, web design began in ~1994 when html began. Around that time, most monitor is 640x480. around ~2005 it's 800px width. 2010 it's 1020 width (by now, laptops is most common). most professional web sites use fixed layout. i.e. design for specific screen width.

also, flowed layout is pretty much favored by nerds or programers, who focus on logical structure. e.g. chapters, sections, subsections. Fixed layout design, is favored by artists or “designers” (aka desktop publishing of 1990s on Mac), because it's pretty.

note, CSS was invented in 1996 but isn't used widely till ~2002. The thinking about flowed vs fixed layout was that, always markup by logical structure, but use css to make the design/layout. this is actually a myth to this day.

Other than academic papers, vast majority of commercial sites do not have any natural logical structure. The “logical” markup is just a artificial pretense. This can be seen today especially with so-called “single page app”. #css #design

CSS: Display Table on Small Screen (major update)

HTML: Viewport Meta

discovered CSS unit “cap”

css cap unit 2018-11-07 5c24b
css cap unit

discovered CSS unit cap. i thought it'd solve the font size problem. But very disappointed. It's a CSS length value. Not a property. We need a property, e.g. font-cap-size:16px.

see Meaning of Font Size

CSS: Units (more major update.)

CSS unit is incredibly complex.

HTML: the Root Element (new)

“Alien heads found in Georgia”. 'was the origin of name of the font Georgia.

CSS: font-family

CSS: font-family

css font family 2018-11 a80a8
CSS font family 2018-11

CSS for beginners. Filling up my CSS tutorial so it covers all commonly used properties. Now, the font topic is complete

  1. CSS: Font Weight
  2. Google Webfont


Font Size problem (on its own page)

Donald Knuth, Steve Jobs, and How Typography Sucks

CSS: Computed Style

Meaning of Font Size

CSS: font-size

all updated or rewritten

Standard Web Fonts (updated. added JavaScript to show what font your browser is actually using.)

2018-11-02 Turns out, it is impossible to find out programatically what font is actually used.

CSS: Display Table on Small Screen

DOM: Basic DOM Methods (minor update)

jQuery Tutorial by Example (minor update)


HTML Tutorial Complete update.

obsolete html5 tags

these html5 tags are now obsolete

and <hgroup> , w3c says no, whatwg says it's good.

updated HTML5 Tags Complete List

List of HTML Self-Closing Tags updated

HTML/XML Entity List (convert table to list. easier for phone screen)

HTML5 Tags Complete List (minor update. convert table to list. easier for phone screen)

Case Sensitivity of HTML5, XML, CSS, JavaScript

added the case for css.

CSS Selector Syntax (rewrite)

Atom Webfeed Tutorial

JS: String.prototype.replace

major update. added list of special chars in replace string, and example of replace all.

JS: Reflect.ownKeys. updated

BigInt is coming to JavaScript.

CSS: Units better explanation of vw

CSS: Fixed Aspect Ratio

JS: Find element Size

improved writing, links.

DOM: Difference Between textContent, innerHTML, innerText, nodeValue

updated to es2015

CSS Pseudo Class vs Pseudo Element

CSS Pseudo Class vs Pseudo Element

JS: Prototype and Inheritance

major rewrite. and also

Chinese website, trying to prevent people from copying the lyrics

chinese website hide lyrics 2018-07-25 e5eb5
lol. Chinese website, trying to prevent people from copying the lyrics.

note, lyrics sites, is contentious. In past 10+ years, many sites tried to be THE lyrics site. The internet things is that, at first, it's legally edgy (e.g. google image search), but after a while, everybody's doing it, unstoppable, became popularity contest.

then about 3 years ago ~2015, Google wiped them all out. Now when you search lyrics, google shows snippets right there, linked right to google lyrics page with Google music store.

JavaScript dom pain. what's the point of querySelectorAll if result is not live?

#JavaScript dom pain. what's the point of querySelectorAll if result is not live? e.g. u have a list, you found the item, want to color red. you can't cuz it's not live. workaround: add id to each element. Now, get the id of found item, then by id, color it.

js query select solution 2018-07-25 1752e
js query select solution 2018-07-25 1752e

JS: RegExp Tutorial

improved writing. More examples.

JS: Reflect.apply

JS: Symbol Tutorial (minor rewrite)

What's the difference between __proto__ vs getPrototypeOf()

see JS: Object.prototype.__proto__

JS: Class

now extensivly modified. Now, it is complete.

the following are in draft stage:

JavaScript class without keywords class new this

JS: Class updated

Shadow Dom

here's shadow dom. https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM

it seems rather useless. the purpose is to define custom tag such that you can use it like <xyz>…</xyz> without lots nested tags and css.

JS: const Declaration (updated to include info about prevent add/delete/change properties)

WHATWG vs W3C Split

For the past 30 years, unix hacker types are FOR “Standard”. They'll flash the STANDARD card, usually in context of dissing Microsoft. In past 10 yrs, the millennials gen, not so much. Look at JavaScript scene, npm, git, github, react, d3js, pop is king.

a glimpse into reactjs innards


Web Design Index

HTML Validation, History and Politics

what's with ./ in front of relative path?

in recent years, the web standard or such seems to require ./ in front of relative path, e.g. <script type="module" src="./main.js"></script> else it's error. anyone know why? link? thanks

See also: JS: Import/Export

wtf does this mean in JavaScript? 「const { PI } = Math」

wtf does this mean in JavaScript? const { PI } = Math;

am so fk sk of js fk.

turns out it's destructuring assignment. very creative use.

[see JS: Destructuring Assignment]

it's destructurining no structure. imagine that. Why the young idiots can't write

const PI = Math.PI;
const { PI } = Math;

jesus, it's 1 char longer. #JavaScript

by the way, its from a example code of nodejs's official doc on module https://nodejs.org/docs/latest-v10.x/api/modules.html#modules_modules

JavaScript framework popularity 2018

js framework popularity 2018 be65e
JavaScript framework popularity 2018. Reactjs is way ahead. everything else is history [image source https://www.npmjs.com/npm/state-of-javascript-frameworks-2017-part-1]

speed comparison: creating element vs creating object

does any know the cost of creating obj and DOM element? not talking about inserting dom into the page, or causing it to render. just about creating dom off page. how expensive is it?

i didn't get any useful answer.

here's a simple test.

// 2018-07-04
// simple speed test comparing speed of
// creating element and append child
// vs
// creating empty object and append to array

const nn = 5000;
const xx = document .createElement("div");
const start1 = new Date().getTime();
for (let i = 0; i < nn; i++) { xx.appendChild (document .createElement("div")); }
const end1 = new Date().getTime();
const result1 = ( end1 - start1);

const yy = [];
const start2 = new Date().getTime();
for (let i = 0; i < nn; i++) { yy.push ({}); }
const end2 = new Date().getTime();
const result2 = ( end2 - start2);

console.log (  result1 , result2)

// it seems creating element is few times slower than creating empty object...
loading react from nodejs 2018-07-02 44414
loading react from nodejs 2018-07-02

JavaScript Graphics Lib Geometry Intermediate Language Problem

js svg lib geometry int lang problem 346a6
JavaScript Graphics Lib Geometry Intermediate Language Problem

one major problem in designing a #JavaScript lib for graphics is whether to have a intermediate language. #d3js says no, but now studying #reactjs, it says yes. #svg

it seems, studying #reactjs provides many answers to my javascript graphics framework design problems. am inclined to believe in reactjs ways, and screw the #d3js fak

the best reactjs tutorial

the best #reactjs tutorial is this https://reactjs.org/docs/hello-world.html this is best for, you are already expert of JavaScript, and you want to understand exactly what react does. Not some do this get that style of tutorials that's everywhere.

CSS: Display Property

CSS Display Property tutorial, first draft. CSS is one of the most complexxx fk

CSS: 2D Transform

JavaScript terminology, data object? object object?

ok, the JavaScript spec calls “data object”, e.g. {key1:1, key2:2}, as “object object”. ok, that's the jargon am gonna stick with.

JS: Object Type

Jargons Explained: Tag, Element, Node, Object, Attribute, Property, Method

Visual CSS major rework.

css border 2018-06-23 13a50

CSS: Border, Outline. new

CSS: Margin vs Padding. updated

CSS: Box Sizing

CSS: Media Query (minor update)

CSS: calc

JS: Character, Code Unit, Code Point (major rewrite)

functional programing math unit vector speed quiz

2 #math unit vector f in #JavaScript. the 2nd works in any dimen. Quiz, their speed diff is constant or linear, for n calls of 2d vector input?


console.log ( f([3,4]) );
console.log ( g([3,4]) );
console.log ( g([3,4,5]) );

// [ 0.6, 0.8 ]
// [ 0.6, 0.8 ]
// [ 0.4242640687119285, 0.565685424949238, 0.7071067811865475 ]


vote at https://twitter.com/xah_lee/status/1007537943894896641

CSS: Background Image (updated)

#javascript a tale of 2 styles

const unit_vector1 = (([v1,v2]) => {const len = Math.hypot(...[v1,v2]); return [v1/len, v2/len];});

const unit_vector2 = (([v1,v2]) => ((len) => [v1/len, v2/len])(Math.hypot(...[v1,v2])));

which you prefer? reply or vote on twitter at https://twitter.com/xah_lee/status/1004578264046661632

const reverse_obj_key_val = ((obj) => {
// given a obj, return a new obj that has its key and value reversed. If values are not unique, the previous is overwritten. 2018-06-04
const result = {};
Object.keys ( obj ). forEach ( ((x) => { result[obj[x]] = x }));
return result;

JS: Class

major update

JS: Operator “new” (added a typical use example)

2018-06-01 to read Content Security Policy

hideous colors, spurious animation

[utc is enough for everyone right By Zach Holman. At https://zachholman.com/talk/utc-is-enough-for-everyone-right ]

Hideous colors, spurious animation. And, it crashes old browsers even with js off.

JS: Timing JavaScript Code (minor update)

JS: the Map Object Tutorial (minor update)

WebSocket Tutorial (minor update)

JavaScript UI: Shake Element (updated for ES2015)

Web Design Index (new index on web design, UI design, articles)

JS: Date Constructor (updated)

JavaScript: Floating Box Following Scroll

JS: Digital Clock (updated to ES2015)

stupid firefox, utf8 still not default

firefox utf8 not default 2018 05 21
stupid firefox, utf8 still not default

See also: HTML: Character Sets and Encoding

skeleton screen

Web Design: Skeleton Screen

UI design, pie menu

[Pie Menus: A 30 Year Retrospective By Don Hopkins, Ground Up Software. At https://medium.com/@donhopkins/pie-menus-936fed383ff1 ]

am fond of pie menu. in Second Life, which i lived in from 2007 to 2012, uses pie menu. It's simpler, easier, faster to use.

perhaps it's fair to say, the spirit of pie menu today lives in phone ui, e.g. a bunch of spacial squares, especially in Microsoft Windows 10's window menu, or somewhat in browser menus at right top corner.

by the way, the author Don Hopkin is a emacs oldbie. He ported sim city to x11. He wrote

The X-Windows Disaster

a chapter in The Unix-Haters Handbook. see The Unix-Haters Handbook

note, it used to be, any hacker have read them. Along with Worth Is Better.

he ranted on emacs change to visual lines, 5 years ago.

Rants on Emacs Visual Lines by Don Hopkins and Mark Crispin

this is originally posted to reddit discussion https://www.reddit.com/r/emacs/comments/8kkite/history_pie_menus_a_30_year_retrospective_don/dz9vozi/

JavaScript Books Review 2018

major update



CSS Variable


phone browser opaque smart behavior

seems there's opaque algorithm when phone browser renders html. e.g. a nav bar with #css position:fixed to top left, then android chrome may or may not hide it after scrolling down, depending the page's height. is there doc about how phone special treatment of css?

nice article, on css variable


don't use .io domain

so, if you use a .io domain, you are in trouble. Note that, the programer idiots love special domains, started with .cx , de.licio.us etc. and since about 2010, .io. the thing is, the fad come and go.

see https://www.uptimechecker.org/blog/how-domain-registrar-can-kill-your-business

JS: Property Key (updated. replace var with const)

js user object parent nqnqn
JavaScript, parent of user created object

JS: Prototype and Inheritance

JS: How to Create Tooltip (updated)

JS: Function.prototype.bind (minor update)

JS: How to Use Object.create() to Emulate Constructor? (minor update)

JS: Pipe Function Instead of Method Chaining (code update)

JS: Semicolon Rules (updated)

JS: Allowed Characters in Identifier (updated)

JS: Object.prototype.valueOf (minor update)

JS: Property Attributes, writable, enumerable, configurable

JS: Object.defineProperty

minor updates.

JS: Branch Control: if then else, switch

JS: Property Dot Notation / Bracket Notation

Minor updates. Now uses const instead of var.

JS: Format Number

D3.js Visualization, a Quasi Science

[How Likes Went Bad By Matt Locke. At https://medium.com/s/a-brief-history-of-attention/how-likes-went-bad-b094ddd07d4 ]

haven't read the whole carefully but it's on the ballpark.

JS: String Escape Sequence (new page)

JS: Unicode Escape Sequence (updated)

JavaScript Basics (updated)

JS: Get Max/Min Value of Array (minor update)

JS: Scripting SVG (updated)

JS: Operator “new” (updated)

JavaScript, Design Patterns Appoach to Computer Language Tutorials

JS: Object Constructor (updated)

JavaScript Map Filter

JavaScript quiz of the day. write a map_filter(map_obj,f). Returns a new map where f(key,value) returns true.

see JS: the Map Object Tutorial


JS: Map Filter

HTML: Input Range Slider (updated)

JS: var Declaration Order (updated)

JS: “typeof” Operator (updated)

CSS: Units (updated)

Why DOM Suck

JavaScript DOM SVG font-size sucks

SVG: Font Size (new page)

JS: Split Array (new)

JS: Define Function (updated)

JS: Template String (updated)

JS: String Overview (new page.)

JS: var Name Scope (updated)

Color articles has all been updated.

JS: var Declaration (updated)

JS: Global Variable

JS: Closure

JS: “instanceof” Operator (updated)

JS: Primitive Value

worked a lot on my js tutorial. To streamline them, make it easier to find info as practical reference when coding. Going to post 1 updated article a day.

updated to ES2015

JS: Function Declaration vs Function Expression (minor update)

JavaScript Module, and Math vs Programing


JavaScript Math and Plot Libs

several math and plot related js libs to read.

all these are probably very good.

d3 and rollup.js https://bl.ocks.org/mbostock/bb09af4c39c79cffcde4

d3 https://github.com/d3/d3

function-plot https://github.com/mauriciopoppe/function-plot/

mathjs http://mathjs.org/index.html

stack.gl http://stack.gl

plotly.js https://github.com/plotly/plotly.js

propel https://github.com/propelml/propel

complex function phase portrait https://www.shadertoy.com/view/XsVczh

JavaScript ES2016 ES2017 ES2018 ES2019

js is moving fast.



#JavaScript quiz of the day. Write a splitArray(array, f), where f return true means split point. Result does not include split point elements and no empty array. e.g. splitArray([0,1,2,0,4], x => x === 0) returns [[1,2],[4]]

to my patreons, an intro to Xah Lee, is that right?


JS: Object.keys (updated)

JavaScript Find Element in Array

JavaScript has:

worst design possible. Some return index, some boolean, some take function. Most can't deal NaN or undefined.

also, there's no function that finds all occurrences.

see JS: Array.prototype

JS: for-in Loop (minor update)

this is a stupid icon design.

disibility aid options icon 2018 03 05 11937
disibility aid options icon on MacOS, 2018-03-05

In the 1990s, the icon is a wheelchair. It is iconic. People can recognize what it means. But due to political correctness, it is changed to a human animal with arms wide posture. This happened to Mac, Microsoft Windows, and Linux.

also, the word “disabled” such as “disability options” is changed to “accessibility”, also incomprehensible.


SVG Transform Bug in Mac Safari Browser

oh futter. svg v.1.x still have problems. if you attach a transform attribute to the top svg element, it doesn't work in Safari browser, but works in Chrome and firefox. Took 1 hour to debug this futter.

DOM: Change CSS (updated)

Xah Web Dev Blog Archive

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog