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
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# JSON/CSS Module notes
2
-
JSON and CSS modules provide several ergonomic benefits for web component developers. They provide easy integration into the JavaScript module graph with automatic deduping of dependencies, and eliminate the need to manually manage `fetch()`es or pollute the DOM with extra `<style>` and `<link rel="stylesheet">` elements.
2
+
[JSON modules](https://github.com/whatwg/html/pull/4407)and [CSS modules](https://github.com/w3c/webcomponents/blob/gh-pages/proposals/css-modules-v1-explainer.md) provide several ergonomic benefits for web component developers. They provide easy integration into the JavaScript module graph with automatic deduping of dependencies, and eliminate the need to manually manage `fetch()`es or pollute the DOM with extra `<style>` and `<link rel="stylesheet">` elements.
3
3
4
4
However, there are also important quantitative performance advantages to JSON and CSS modules over the current equivalents. This document describes these advantages and illustrates them with code samples.
5
5
@@ -63,9 +63,10 @@ With JSON modules, on the other hand, browsers can initiate
63
63
the fetch for a JSON file as soon as the importing module is parsed, prior to module linking or execution. [Demo 1](#Demo-1) illustrates this difference.
64
64
65
65
## Demo 1
66
-
### Fetches for JSON and CSS modules starts before script execution
(The JSON modules demo requires Chrome or Edge launched with --enable-blink-features=JSONModules).
69
70
70
71
This demo compares two similar custom elements written as a JavaScript module, each of which requires a JSON resource. The first custom element consumes the JSON by `fetch()`ing it, and the second by `import`ing it as a module. For both custom elements, an additional `busyWork.js` module is included in the module graph before the module containing the custom element definition. This is a stand-in for any arbitrary script that might appear in the module graph prior to the custom element definition, such as a JavaScript libary.
71
72
@@ -78,8 +79,10 @@ In the `fetch()` version of the custom element, the JSON file isn't fetched unti
78
79

79
80
80
81
## Demo 2
81
-
### CSS modules vs <link> elements in shadow roots
(There is no general CSS modules browser support as of this writing; that part of the demo was developed on a custom Chromium build).
83
86
84
87
This demo compares two similar custom elements written as a JavaScript module, each of which loads its styles from a separate `styles.css` file. The first custom element applies its styles by adding the styles via a `<link rel="stylesheet">` in the custom element shadow root. The second loads its styles via a CSS module.
0 commit comments