Example WebComponent feature.
- Split html file
- Reuseble component
- Scoped CSS
$ yarn
$ yarn http-server
$ open http://127.0.0.1:8080/
-
Create component file like
/components/xxx-xxx.html
.<div>Hello World!</div>
-
Add component name(
xxx-xxx
) inmain.js
.- Working on
customElements.define(...)
in logic
- Working on
-
Use
xxx-xxx
component inindex.html
.<html> <xxx-xxx></xxx-xxx> </html>
-
Open
index.html
and then render 'Hello World!'.
- Easy way to use component as custom element.
- No need 3rd party library.
- Vanilla JavaScript and HTML.
-
Network latency would happen in this way because JavaScript try to fetch each component html files. If we bundled files into one file, such a problem wouldn't happen.
-
Waiting time happen untill custome element load and render.
# Case1
$ open examples/1/index.html
# Case2
$ yarn start
$ open http://localhost:8080/examples/2/index.html
# Case3
$ open examples/3/index.html
We cannot open .js file via .html because of security feature in browser.