Use the "scoped" attribute for CSS and JS #1056
-
I was reading the docs and this page in particular... https://viewcomponent.org/guide/javascript_and_css.html I really love where ViewComponents is going! Same benefits as React, but much simpler and clean (like Rails). However I don't like the custom elements syntax... Mixing the CSS with Javascript and a markup duplication between the JS file and the HTML file. Why not just use the For Javascript there isn't a https://discourse.wicg.io/t/script-tags-scoped-to-shadow-root-script-scoped-src/4726 It seems that there is also a polyfill that we could use right now. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
AFAIK CSS doesn't have a modern supported Styles encapsulated within the Shadow DOM is the web-native official method of scoping CSS. While in the docs example the scoped CSS in contained within a JS file as is common in a lot of web components written out in the wild, there are methods you can use to write a separate CSS file which is then loaded in by the component. The best method IMHO is just starting to roll out called "Constructible Stylesheets". I'm not 100% certain but I believe there's a polyfill available for that. More info: https://github.com/WICG/construct-stylesheets |
Beta Was this translation helpful? Give feedback.
-
Closing. We have decided not to explicitly support any particular CSS/JS architecture due to the frequent churn in those areas. |
Beta Was this translation helpful? Give feedback.
Closing. We have decided not to explicitly support any particular CSS/JS architecture due to the frequent churn in those areas.