Skip to content

Commit

Permalink
Improve HTML rendering performance
Browse files Browse the repository at this point in the history
Couple lines of CSS cut page loading and resize times
by 100 times (on my machine).

Description of what content-visibility is: https://web.dev/articles/content-visibility
Basically browser now doesn't render/layout invisible sections.
As a downside it makes scrollbar jump around slightly 
when you scroll the page, as browser recalculates the layout.

Section size was calculated using the following JS code:

const getAverage = (arr) => arr.reduce((p, c) => p + c, 0) / arr.length
getAverage(Array.from(document.querySelectorAll(".sect1").entries().map(([idx, el]) => el.getBoundingClientRect().height )))
getAverage(Array.from(document.querySelectorAll(".sect2").entries().map(([idx, el]) => el.getBoundingClientRect().height )))
  • Loading branch information
kanashimia authored Dec 25, 2024
1 parent b04fc6a commit 2a22bc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/khronos.css
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,9 @@ li > p > a[id^="VUID-"].link { color: black; text-decoration: none; }
li > p > a[id^="VUID-"].link:hover { color: black; }

.vuid { color: #4d4d4d; font-family: monospace; }

/* Improve page rendering performance */
/* contain-intrinsic-size is the approximate average height of all sections */
.sect1 { content-visibility: auto; contain-intrinsic-size: 98000px; }

.sect2 { content-visibility: auto; contain-intrinsic-size: 13000px; }

0 comments on commit 2a22bc2

Please sign in to comment.