You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -81,21 +81,21 @@ A custom element that pulls in its styles with CSS module, however, only process
81
81
82
82
[Demo 1](https://dandclark.github.io/json-css-module-notes/demo1/index.html) illustrates this difference with a custom element written 3 different ways: with a `<style>` element in each shadow root, with a `<link>` element in each shadow root, and with a single CSS module applied to each shadow root's `adoptedStyleSheets`. To make the performance differences easily distinguishable, each page includes 15,000 instances of the respective custom element version.
83
83
84
-
I generally observe the CSS module element version loading about 1 second faster than the `<style>` element version, though the difference will vary per machine.
84
+
The following graph is characteristic of the results:
85
85
86
-

86
+

It's not clear why `<link>`is so much slower; caching should prevent it from making a new network request for each element instance. There might be a Chromium bug here, but in any case we expect that the performance best case should be similar to the `<style>`version.
94
+
These results make sense; for the `<link>`and `<style>` approaches, each custom element instance must have its own instance of one of these elements. It takes time to allocate this element, and process its various rules for insertion into the DOM tree. For example, setting up all of the StyleSheet fetches for the `<link>`element approach takes a nontrivial amount of time even though they all end up hitting the cache. With CSS modules on the other hand, there is just a single CSSStyleSheet instance for the entire page.
95
95
96
-
There are also memory savings from omitting the extra elements. After reaching baseline (putting tabs in background and waiting for final GC at ~60 seconds) I see these numbers:
96
+
There are also memory savings from omitting the extra elements. After reaching baseline (putting tabs in background and waiting for final GC at ~60 seconds) I see these numbers like this:
### Demo 2: [CSS/JSON modules have a lower memory footprint than inlining the CSS/JSON as a JavaScript string](https://dandclark.github.io/json-css-module-notes/demo2/index.html)
0 commit comments