Essentially Astro lets you build sites using a JS framework like React or Vue without requiring that framework to be loaded on the frontend. By default, components are just HTML content. Super nice for building very fast static sites using a technology you may already be fluent in.
You can still add interactivity to components if you'd like—just tag components that require interactivity and Astro will bundle the requisite JS for the client.
Having that productivity and flexibility without the SPA complexity and other JS cruft has real value.
a. A completely static site with no frontend javascript and no client side hydration, or
b. client hydration in which case all the components needed in the page will need to be loaded in the client.
If you want something in between, ie. only some sections need to be interactive, it requires jumping through some hoops eg. creating separate webpack entrypoints that call ReactDOM.render for specific DOM nodes. It is doable but more work and maintenance effort.
Astro simplifies handling for these kind of islands by using a server side templating language that is component aware and familiar to users already writing jsx.
But React (like Vue and Svelte) are fundamentally about interactivity. If I had a project where I knew for sure that I only wanted to generate HTML sans JS on the server (or with a static build process) I wouldn't even consider using React.
It barely even makes sense. Your "React components" would just be JavaScript functions that take props and return some JSX. None of the interesting React features and hooks would even make sense, other than maybe context (and presumably most or all popular static HTML templating tools have comparable features).
If you are building a growing design system with any degree of complexity, React is one of the best tools available.
<%~ includeFile('./navbar', { pages: [
'home',
'about',
'users'
] }) %>
<navbar pages={['home', 'about', 'users']} />
> would just be JavaScript functions that take props and return some JSXThey can also be async functions that process data independently. Whereas templates are commonly just passed in data from the controller.
I mean if JSX is considered as something particularly powerful (not saying it does) doesn’t Vue actually do that https://vuejs.org/guide/extras/render-function.html ?
For static sites, this means that you get functions and objects the entire way through the render pipeline right up until there is a full tree built and the final output is rendered.
You still get all the separation powers of contexts, the component based reusability, etc, and it is all regular JavaScript / typescript except for the JSX macro itself and React's APIs (which are just JavaScript). Conversely, with templating engines like handlebars / erb / et al you need to learn the specific DSL of the template engine- custom loops and controls, imports for partials, and your custom helpers are limited to what they can do. Even Vue's render function has special markup for control (v-if, v-else).
Plenty of people were also taught that proper architecture involved an AbstractGetterVisitorFactoryFactory.
That doesn't make either of those things true.
As a side note, if you find yourself wanting a loop but using `map` isn't sufficient, you should probably be preparing the values ahead of time and still using map. It'll be more efficient, and the code easier to read.
PHP intermingled with HTML was bad because developers would do things like run database queries and other operations that caused side effects directly in the markup. Every templating system still has logic in it, and almost every templating system as a way to create custom helpers which are written in the host language.
Since API calls and calls to react's `setState` are asynchronous, and the rendering pipeline is synchronous, it is still obvious that you can't put code that makes an AJAX call in your html markup.
In short, you can do those things maliciously, but if you do them naively it is immediately obvious when you run the code that it's not correct.
Compare that to the original analogy to mixing raw PHP and HTML templates. Since the rendering process is blocking, you can easily stuff form handling, remote API calls, and database calls in amongst your markup, and can make it "work" even if it's not clean.
Even Laravel's blade components let you write custom components and helpers in PHP which can do all of those things from the template- you just don't see the actual SQL mixed with the HTML in the same file. The problem is still there, just now it is harder to see.
Is that a joke? You get autocomplete from typescript and props to be fully typed functions, or any kind of object for that matter. That compares to autocomplete that's just some ad-hoc, bug ridden tools that locks you into some IDE or editor, and who cares because all the attributes have the same type (string) anyway.
Specifically I can think of parts of the websites' functionality is editing highly technical structured data documents by highly trained domain experts.
I mean basically where years of developer productivity was thrown down a React hole when it could have been months in SGML / XML based tooling for what was required.
I can say that because I have built big solutions in both stacks, though.
My bash scripts are often edited, I could not imagine using a compiled language where I would have to store the source as a separate file from the executable, then compile it each time.
I'd love to know your more specific use cases, if you don't mind. I'm always happy to learn something new. Could you share some Rust that most people would script in Bash as an example? What's your build and deploy (to ~/.local/bin I presume) strategy?
> What's your build and deploy (to ~/.local/bin I presume) strategy?
You can run scripts as you would with bash, you don't have to manually build and run the executable. For example, `cargo run (inside the script source folder)` and `sh script.sh` do basically the same thing, end user wise. `nim compile --run script.nim` is similar in that the language compiler will automatically compile and run it together.
> Could you share some Rust that most people would script in Bash as an example?
I was creating dotfiles the other day and I didn't want to use some dotfile manager program as I had some specific steps I wanted to follow, so I started it as a bash script. Well, it got kind of annoying so I made it into a Rust script with some nice features like interactive prompts, text coloring, etc with libraries like `clap`. You can do this in bash of course, but the Rust version was more ergonomic. When I need to run the script, I just did `cargo run` and it worked great.
For instance, my most-used bash script takes a file as input and opens either VIM or Emacs depending on whether the file is a .md or .org (simplified example). I run it like so:
$ n foo.org
I can edit ~/.local/bin/n and update the file, and use it immediately. I actually have my whole ~/.local/bin in version control. Having to type out e.g. $ nim compile --run n foo.org
...would make the whole experience far less fluent. I probably would never use it.I'm asking because I'd love to rewrite this script in e.g. Rust, but I don't see any good way to deploy it to ~/.local/bin/n.
eg:
$ code script.nim
#!/usr/bin/env nimcr
echo "hello world"
$ ./script.nim
hello world
edit:There's also the possibility of using nimscript, using nim e. It works similarly but you'd change the shebang line to something like
#!/usr/bin/env nim e --hints:offIn config.nims:
switch("hints", "off")
task hello, "say hello world":
echo "hello world"
In bash: $ nim hello
hello world type ADT =
| { case : 'a', a : Number }
| { case : 'b', b : string }
function f (c : ADT) {
switch(c.case) {
case 'a' : return c.a
case 'b' : return Number.parseInt(c.b)
// case 'c' : return 0 // compile error
// case 'b' : return c.a // also compile error
}
}I'm not a web dev by trade but I have a website for a hobby project. I had taught myself React thinking I might make an app. (I never did.)
So now I want to maintain this thing on the side with not much effort using what I already know. And that keeps those skills fresh, which is great.
I'm very interested in Astro.
I think this is the only selling point, given the "content-focused". It's not different than just writing HTML and vanilla js for some interactivity.
A basic counter component would look something like this:
initial_state do |props|
{ count: 0 }
end
handler(:increment) do |e|
update do |count:|
{ count: count + 1 }
end
end
render do
<div>
<p>Count: {state[:count]}</p>
<button on-click={handler(:increment)}>Increment</button>
</div>
end
There are some things I'm used to in the JavaScript world that I'm trying to introduce here. I got hot reloading which is pretty cool. And CSS modules... and static typing with Sorbet.Events are handled on the server, so there's no need for an API... You could just talk to your database directly in your onsubmit-handler. I think that might be the largest benefit from using something like this.
If the app is deployed in a region close to you, you won't barely notice the latency.
With Hugo and Jekyll I always needed to go revisit the docs whenever I hadn't worked with it for a while. I never got to the "oh, I get this tool now" phase, where the content generation could just flow without issues.
Publii was cool, but trying to shoehorn everything into fitting in the "Blog" model never quite worked out for me. Also being forced to work in a new IDE wasn't to my liking either.
Here are some of the things I love about Astro:
- The docs are great. You can read through them all really quickly. I tend to prefer systems that are simple to grok, and Astro is just that.
- The lightweight Astro components (https://docs.astro.build/en/core-concepts/astro-components/) were great for me, because they delivered on being able to create reusable pieces of code very easily (without having to touch React).
- Being able to generate part of your site from markdown and part of it from precisely crafted HTML is a great way to be able to handle both repetitive and unique content.
- The Astro themes (https://astro.build/themes/) are a great way to start. Find something that's somewhat similar to what you want to build and study how they did it.
This is obviously very subjective, but for me Astro was the first SSG that I really enjoy using, and that I didn't feel like I had to fight against.
Why do you hate it? It's useful to have a term to differentiate between the experience of the person using the output of the tool (user experience) versus that of the people developing with the tool (developer experience).
Honestly we need more DX improvements in this industry. Especially look at DevOps - the user experience of Chef's output (I'm picking on Chef here, it's hardly the only offender) is servers and services, and the users (other engineers) consuming those outputs can have a nice time. The DX of using Chef, though, can be ughh....
Nope, we need to roll back everything that happened in the last ~10 years. We at the very least need to stop sticking JS and the web stack everywhere. Use the right tool for the job, NOT pick up a shiny tool and try to do literally everything with it. NOT stumble upon solution and start looking for problems to it. Finally realize that software engineering is actual engineering that, like other forms of engineering, has a sizable impact on other people's lives. Unlike in other forms of engineering, the cost of a mistake might feel diminutive enough, but people do suffer trying to use modern software products. I wish I was joking.
I also hadn't had any coffee in way too long, so I have to admit I was a bit grumpy at the time of writing the comment :)
It might be overused, that’s an opinion, I don’t agree.
There is also this page comparing it with other tools: https://docs.astro.build/en/comparing-astro-vs-other-tools
* unless something changed since my last Nuxt project
Might even sneak in a fourth level, "server side, but cached until marked dirty". For when you are set up for static rendering, but want to reduce backend load for rarely changing stuff. I'd expect that it would be quite powerful to have that capability inside the engine that handles rendering, on component level if necessary,and not just on some internal microservice boundary (where I think it's quite common?).
Apparently there has been quite a watershed moment, with the announcement merely a few months ago: https://astro.build/blog/experimental-server-side-rendering/
This gives some more examples of what Astro offers https://twitter.com/matthewcp/status/1557103499724333057?t=8...
It's just a faster way to build UI's that don't need the full complexity of a SPA and also don't need to come bundled with the entirety of react from what I've seen and used it for.
Not really sure when to play around with these new frameworks if it's not giving me enough reason to switch, especially since they're not adopted in big tech companies it makes it harder to justify the usage when I want to build somethjing
I feel that this is what I was looking for https://docs.astro.build/en/concepts/why-astro/
> Next.js uses React to render your website. Astro is more flexible: you are free to build UI with any popular component library (React, Preact, Vue, Svelte, Solid and others) or Astro’s HTML-like component syntax which is similar to HTML + JSX.
> Both Next.js and Astro are frameworks for building websites. Next.js does best with highly dynamic websites (like dashboards and inboxes) while Astro does best with highly static websites (like content and eCommerce websites).
https://docs.astro.build/en/comparing-astro-vs-other-tools/#...
If you need backend api functions - https://github.com/serverless-nextjs/serverless-next.js/ AWS Lambda etc. Probably slightly more work I grant you.
Plus, both Next and Remix are tightly coupled with React, whereas Astro is trying to be more agnostic in that regard.
I acknowledge that this might be a PEBKAC situation, but I'd love to hear thoughts from people who used Next.js, Remix, or whatever and found Astro to be a revelation.
It seems like Astro's creators believe "content-focused" is a differentiator, but I find that confusing since content-focused sites are a popular use case for web frameworks that are also suitable for more complex apps.