Welcome to the second episode of "This week's finds" - the series where I share my findings in the past week. Let's start with few features included in the newest ECMAScript specification which just got formally approved.
String.prototype.replaceAll
How often do you find yourself using the "replace" method with RegExp to globally replace occurrences in a string? Soon you will not need to do it anymore, as we will have a built-in API for it. The functionality will be basically the same as the previously mentioned method, the only difference is, as the title suggests, all appearances are replaced.
Logical assignment operators
This thing will combine logical operators with assignment expressions. For example, it will be possible to use "x ||= 3", which will assign a new value only when the variable was falsy before. The newest addition will make it a breeze, without needing to worry about unnecessary assignments. I personally think this functionality shouldn't be underestimated. Frameworks like Vue or Svelte use assignments as their reactivity system core. Because of that, we can sometimes use those operators to reduce the amount of unneeded JavaScript execution.
Other additions
Besides these two which I have mentioned, we have few more new features. Just to give you a glimpse of what's incoming - separators for numeric literals, new ways of working with JavaScript garbage collection system, and additions to promises. You can always take a look at the full specification, which can be found here.
Astro - Ship less JavaScript
Astro is a new kind of meta-framework for building web applications nowadays, coming from creators of Snowpack and Skypack. Actually, it has been around for a few weeks already, but I couldn't stand up not describing it on my blog. Starting slowly, it's a static site builder that conjoins excellent performance with modern developer experience.
One of the main selling points of Astro is "BYOF" - bring your own framework. Whether you enjoy React or Svelte or Vue, you don't need to abandon your current knowledge. You can build the Astro app on top of all you know already. Thanks to a thing called "renderer" it's possible to just plug in our favorite framework (if there is existing integration of course, currently they're supporting React, Preact, Svelte, and Vue, but there is already PR for StencilJS support). You can even use their own format, which for me resembles a mix of JSX and Markdown.
Furthermore, an aspect of Astro that makes me enthusiastic about it is its "Island Architecture". Basically - your app is deprived of any JavaScript, everything is rendered statically by default. Of course, sometimes we need JavaScript for these slick interactive parts of our websites. Though how the catchphrase suggests - these are often just "islands" on the sea of our app. Besides, there is even a built-in method for only loading these components that the user sees. Also, there is a possibility to load interactive parts when the main thread is actually free and ready to parse them.
Moreover, the whole framework is built with SEO in mind. Automatic sitemaps, RSS feeds, pagination, all these things are a piece of cake with Astro. To add to this Astro supports many of the modern frontend tooling, few mentioned by the developers themselves - TypeScript, Scoped CSS, CSS Modules, Sass, Tailwind, Markdown, MDX.
I think that in the era of JavaScript bloat, frameworks like Astro can make a real difference. Even if the possibility that it will get into the mainstream is low - I hope that some patterns can be learned through it. One of the quotes that I found exceptionally accurate is "the framework wars won’t have a winner - that’s why Astro lets you use any framework you want". I invite you to visit the website and learn more about it.
And with that line, we will be getting over this week's episode of the series. Let's hope that next week will not be less productive in terms of my findings. Without further ado, have a nice week!