Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save t0mab/c4a28e9320d7cce9103d99500b4ccf79 to your computer and use it in GitHub Desktop.
Save t0mab/c4a28e9320d7cce9103d99500b4ccf79 to your computer and use it in GitHub Desktop.
2 front-end tips to keep in mind — First published in fullweb.io issue #68

2 front-end tips to keep in mind

1. Stop using .innerHTML = ''; when removing children to a DOM element.

On modern browsers it seems to be about 400× (!!) slower than this DOM-friendly method:

while (el.firstChild)
    el.removeChild(el.firstChild);

2. Simplify your CSS when inlining element.

Often we see or write such code:

.item {
  margin-right: 10px;
}

.item:last-child {
  margin-right: 0px;
}

But truth be told, as we have the :not() selector since IE9+, we could more concisely write:

.item:not(:last-child) {
  margin-right: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment