Make code more server-side friendly #551
Replies: 2 comments 8 replies
-
This discussion already has the viewpoint on supporting SSR in Alpine. #544 In short: Alpine.js is designed to augment server-rendered templates with some client-side JavaScript, it's not designed as an all-encompassing SSR-able JavaScript framework. Note that currently you could precompile/run Alpine.js server-side by using something like JSDOM but since Alpine.js has no virtual DOM (ie. it's tightly coupled to DOM APIs), running it outside of a DOM environment is unlikely to ever be on the roadmap. |
Beta Was this translation helpful? Give feedback.
-
I understand your comment, however I believe we are talking about orthogonal issues. Server side rendering is useful for many purposes, including testing (including alpine's testing code). Not having a virtual DOM means that you need to bring your own (such as JSDOM), which is fine for many SSR purposes. By having (unqualified) references to things like Looking at what Vue does might be enlightening. Reactivity is off by default for example, and directives are only possible through the renderer. Alpine.js has the possibility of being a much nicer SSR environment due to its simplicity. For example, it might not even need a special renderer like Vue. For many reasons (efficiency, SEO) people are going to want SSR, sooner rather than later. The more momentum Alpine.js gains, the more push for SSR there will be. Cheers. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I have been trying AlpineJS and so far enjoying it. A couple of suggestions to make the code more server-side friendly, as I am trying to pre-compile some templates:
Do not rely on navigator existent (on utils.js:19. First condition could be
typeof(navigator) !== "undefined"
.Do not rely on global
window
and/ordocument
to exist. In index.js:17 you could add event listener iftypeof(document) !== "undefined"
.On index.js:23 you could listen for "uninitialized" components "iff"
MutationObserver
is defined.Happy to submit a PR if you are inclined to accept these changes.
Thanks for a great library!
Beta Was this translation helpful? Give feedback.
All reactions