Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active May 28, 2024 22:29
Show Gist options
  • Save nepsilon/baec0992108328c02cd6b3f1744dd1ba to your computer and use it in GitHub Desktop.
Save nepsilon/baec0992108328c02cd6b3f1744dd1ba 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;
}
@tomByrer
Copy link

tomByrer commented Dec 2, 2016

I wonder what the performance differences would be between the CSS selectors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment