Abstract: For front-end developers, the problem that is often hesitant is how to choose a front-end framework. By using JS libraries, development efficiency can be greatly improved, but the author of this article believes that in some scenarios, JS libraries do not bring Multiply the result with half the effort, but get twice the result with half the effort!
Original link: https://ift.tt/g2obqYE
Disclaimer: This article is translated by CSDN, and reprinting is prohibited without authorization.
Author | Sean Schertell
Translator | Meniscus
Produced | CSDN (ID: CSDNnews)
If you’re building a Single Page Application (SPA) like Figma or Trello, utilizing one of these tools can save you a lot of time and money. However, if you are building a Multi Page Application (MPA), such as a common e-commerce website, or even an application like email, then I tell you clearly, the complexity of using a SPA framework Sex is far more than its own worth.
Problems with SPA Architecture
Treating the server only as a channel for calling APIs means that we can no longer rely on it to maintain the state of the application. So we moved all state management to the client, and with that we invented whole new frameworks like Redux and MobX. Since we can no longer use the server for basic routing, libraries like React Router and Page.js were created to emulate the routing functionality that was previously available for free.
Previously, it was very easy to implement authentication on server-side sessions. However, in SPA architectures, where we usually need to use JSON Web Tokens, this implementation is significantly more difficult (and bug-prone). Even the most basic form submission can no longer rely on the browser’s standard HTML implementation to submit form fields based on their name attribute. Now we need to bind these values to a JS object and manage and submit that object “manually”.
In other words, these features that we used to get for free now require a lot of effort, is it worth it?
Why is there the current situation?
In the past, web development was simple. The browser sends an HTTP request, the server sends a new document, and the browser renders it to the viewport, replacing all previous content. However, this method is a bit clunky. This means that even if you only want to update a small part of the page, the entire page must be re-rendered.
User expectations for modern responsive websites have also increased dramatically over the past 5-10 years. As a result, people are no longer content to build “Web 1.0” style applications that require entire pages to be reloaded.
Modern UI without SPA
So how can we build a modern MPA website without using a SPA front-end/REST back-end architecture, without writing lots of clunky JQuery, and without having to refresh the entire page on every mouse click?
If we send HTML as originally designed by Tim Berners-Lee (inventor of the World Wide Web), we end up with a lot of useless data. The DOM of client state management is the state of the client. Client router? Isn’t this a joke? JSON Web Tokens? Server sessions are authenticated and easier to implement. Our database queries are also easier because all routes are written on the server side, so the database can be accessed securely and directly.
I wrote a simple ExpressJS based framework to implement this architectural style, you can try it out: https://www.sanejs.dev.
Will Ruby on Rails shine in 2022?
Like most modern web developers, I’ve been avoiding Ruby on Rails for a long time because the framework was designed to build huge monolithic web applications, which is outdated. The problem is that if the front end uses a framework like Hotwire or HTMX, the back end can use any framework. Since we’re dealing with HTML elements, the backend can ideally choose the framework that works best for creating server-rendered templates. But we don’t have that many full-featured, easy-to-use frameworks. Today’s mainstream frameworks are Rails, Django, and Laravel. There are also some upcoming frameworks such as Elixer-based Phoenix and Go-based Buffalo. But Rails has a large, mature community that, honestly, has helped us a lot.
But the point is that the latest release of Rails 7.0 last December includes Hotwire, a front-end interaction library. Hotwire can be used with Rails or by itself, but it’s designed to work well with Rails development and comes by default. Believe it or not, in 2022 Rails is still the perfect full stack framework for building post-Jamstack MPA web applications with modern interactivity that controls basic HTML elements, we don’t need to resort to JS Framework, build a front-end application plus a back-end API.
If our ultimate goal is to build a modern MPA website in a fast, organized, and maintainable manner, then we should seriously consider whether the SPA/Jamstack architecture is really suitable for the job. With the advent of modern DOM interaction libraries such as Hotwire, HTMX and Unpoly, we finally have a true SPA alternative that allows us to create modern, elegant interfaces that allow us to control basic HTML elements without having to reinvent the app Basic wheels for program state management and form submission. So, if we want to go back to server-rendered templates, it might be time to look again at the reigning champion of web frameworks: Ruby on Rails. Especially with the new 7.0 version with Hotwire built in, Rails may be the best solution for building modern multi-page apps in 2022.
The text and pictures in this article are from CSDN
This article is reprinted from https://www.techug.com/post/is-it-time-to-abandon-svelte-react-and-vuec32db3ee4aa75a967b80/
This site is for inclusion only, and the copyright belongs to the original author.