Open wowselim opened 3 months ago
@wowselim what about creating multiple entrypoints (one for each page) containing the component for that page?
quarkus.web-bundler.bundle.main=true
quarkus.web-bundler.bundle.main.qute-tags=true
quarkus.web-bundler.bundle.page1=true
quarkus.web-bundler.bundle.page1.qute-tags=true
quarkus.web-bundler.bundle.page2=true
quarkus.web-bundler.bundle.page2.qute-tags=true
src/main/resources/web/main/... src/main/resources/web/page1/... src/main/resources/web/page2/...
{#bundle key="main" /}
{#bundle key="page1" /}
You can even have a main containing components on both pages.
I wouldn't optimise too much tough, depending on the case of course, I don't think the overhead is big when having a few more css lines and scripts even if they are not used on that particular page.
@ia3andy with the css it might not be a huge problem but I think with js it's more of an issue especially if you do things like adding event listeners to certain elements. If the element is not present (because you don't reference the component) that's more of a problem and you will have to add checks in your scripts to account for this.
Think about this:
<div role="button" class="my-fancy-button" id="submit-button">Click me</div>
const button = document.querySelector("#submit-button")
button.addEventListener(… // kaboom! button is undefined
Therefore I think it would be really nice to have this feature.
What about the solution I suggested above? I am not sure I see your point, the good thing with the current approach is that your code is minified and optimised (and common code is put in a split shared script), also you can use import libraries and use them. See: https://github.com/ia3andy/renotes/blob/main/src/main/resources/web/components/NoteEditor/NoteEditor.js
@ia3andy with the css it might not be a huge problem but I think with js it's more of an issue especially if you do things like adding event listeners to certain elements. If the element is not present (because you don't reference the component) that's more of a problem and you will have to add checks in your scripts to account for this.
Think about this:
<div role="button" class="my-fancy-button" id="submit-button">Click me</div>
const button = document.querySelector("#submit-button") button.addEventListener(… // kaboom! button is undefined
button?.addEventListener( // boom avoided
Seem to be a good practice anyways https://ricostacruz.com/rsjs/#avoid-side-effects
@all-contributors please add @blazmrak for mentoring
@ia3andy
I've put up a pull request to add @blazmrak! :tada:
@all-contributors please add @wowselim for question
@ia3andy
I've put up a pull request to add @wowselim! :tada:
Hey,
I've been following the guide on the docs and noticed that all the stylesheets for server-side components are combined into one css resource. This means that even if a page only uses one component it imports the stylesheets for all components. I guess this also applies to the js?
https://docs.quarkiverse.io/quarkus-web-bundler/dev/advanced-guides.html#qute-components
Here's the root template:
Here's the css that's included on that page:
Notice how the template doesn't use the sidebar component.