Side Effect Free Templates and Pages (No JS Web Components) #644
Replies: 2 comments 1 reply
-
Actually, another way to think about this could be like in PHP where you can just <?php include 'footer.php';?> This is what I think the old HTML Import spec was trying to achieve, which now has more life to it maybe? But either through a spec or a plugin even, it would be great to make something like this possible, e.g. <link rel="html" href="path/to/some/html"></link> Or maybe we could do it more like a web component I guess, but just not sure how to "link" everything <my-header>
<link rel="html" src="path/to/some/html"></link>
</my-header>
<!-- or -->
<my-header data-gwd-src="path/to/some/html">
</my-header> Both have some pros and cons
And for DX, we could make it so you could either use a JS or HTML file, as long it was just HTML that always came back, and then Greenwood could just straight up insert that into the DOM. without needing any JS at all for say something like a header or footer, even if it just needed JS at build time. 🙌 Some relevant issues to follow along with |
Beta Was this translation helpful? Give feedback.
-
Another idea I had since statically analyzing a component may be brittle, is to use a resize observer that could be used a hydration mechanism, so only include the component definition when it actually scrolls into view. This would be dependent on initial HTML being able to completely bootstrap the browser, including styles, but if an initial HTML payload can be delivered first, maybe that would be enough? That said, would the UI get too janky if WC were just "popping" into place as you scrolled? I suppose a health viewport bottom padding would be needed, but it would be great to somehow "intercept" When using Lit, I think this could be a good use case for a ReactiveController. |
Beta Was this translation helpful? Give feedback.
-
Overview
Had this idea a while ago thought I had captured / mentioned it in either #354 or #305 but effectively, somewhat like through our optimization settings, would nice to see if there's a way to detect if code / components included in a template are "side effect" free, thus they would be marked as
static
automatically and would never be shipped to the user.Basically, this is intending to enhance the more fine grained, user controlled experience of how to manage templates and payloads if you didn't want to involve any form of SSR where Greenwood would try and detect some of the optimization options for you. it's not clear how useful this strategy is if SSR for native
HTMLElement
works out really well, but for anyone wanting to keep it super simple while still wanting to use Web Components + pre-rendering to build their sites / apps, this might be really nice to have.Example
Take for instance these two components from the Greenwood website, the footer and the banner.
Footer
Banner
The footer only needs to run once to generate HTML that can be prerendered and then be static forever, Greenwood might be able to use an AST to see if something not like
setInterval
exists, like in the banner.So the outcome here would be:
static
default
(since we need the JS for the cycle code, as could be inferred bysetInterval
usageCaveats
I'm not actually the full scope of what would be considered not side effect free and / or how practical an endeaver this would be, but I don't mind exploring it for a little bit if folks would be interested. I'm hoping that SSR + Declarative Shadow DOM +
defer
will make for a really nice experience for both users and developers, so will be keen to measure against those efforts as well.Beta Was this translation helpful? Give feedback.
All reactions