Ruby on Rails applications can now run directly in web browsers thanks to WebAssembly. This is achieved using a new project called "Spreetail/wunderbar-wasm", which compiles Ruby and Rails to WASM using a custom-built toolchain. This allows developers to build full-stack Rails apps that execute client-side, offering potential performance benefits for certain applications by reducing server roundtrips. The WASM approach allows for offline functionality and removes the need for separate frontend and backend deployments. While still experimental, this technology opens up new possibilities for building web applications with Ruby on Rails.
The blog post "Now you can run Ruby on Rails on WebAssembly" on web.dev details a significant advancement in web development: the ability to execute the popular Ruby on Rails framework entirely within a web browser, leveraging the power of WebAssembly (Wasm). This achievement opens up new possibilities for richer, more interactive web applications and simplifies the development process in several key ways.
Traditionally, Ruby on Rails applications have resided on server-side infrastructure, handling data processing and dynamic content generation before sending the rendered HTML to the user's browser. This client-server architecture necessitates managing server resources, dealing with network latency, and potentially sacrificing interactivity. With the advent of Rails running on Wasm, the entire application, including the Ruby interpreter, the Rails framework, and application code, can be downloaded and executed directly within the client's browser.
The blog post highlights the collaboration between the Wasmer team and the Shopify team, who spearheaded this effort. Shopify, a major e-commerce platform with a substantial Ruby on Rails codebase, recognized the potential benefits of Wasm for improving developer experience and application performance. By compiling a version of Ruby specifically designed for Wasm, using the Wasmer runtime, they demonstrated the feasibility of running a full Rails application client-side.
This shift to client-side execution offers several advantages. Firstly, it improves the developer experience by simplifying the development workflow. Developers no longer need to constantly switch between frontend and backend development environments, streamlining the debugging and testing process. Secondly, it opens doors for improved application performance and interactivity. Complex calculations and data manipulations can occur instantly within the browser, eliminating network round trips and enhancing the user experience. Thirdly, it presents an opportunity to reimagine traditional web application architecture. The post hints at the potential for hybrid architectures where certain components run client-side while others remain server-side, offering greater flexibility and scalability.
The post showcases a proof-of-concept demonstrating a simplified Rails application running entirely within the browser, handling user input and dynamically updating the content without any server interaction. This example, while basic, illustrates the potential of this technology. The post emphasizes that this is still an early-stage development, but the progress achieved signals a promising future for Ruby on Rails in the browser, potentially revolutionizing web development workflows and paving the way for more sophisticated and responsive web experiences. While challenges remain, including the initial download size of the Wasm module and the performance of certain Ruby operations within Wasm, the advancements outlined in the blog post represent a significant step towards a future where server-side logic can seamlessly migrate to the client's browser, empowering developers and enriching user experiences.
Summary of Comments ( 17 )
https://news.ycombinator.com/item?id=43079791
Hacker News commenters expressed skepticism about the practicality of running Ruby on Rails in the browser via WebAssembly. Concerns focused on performance, particularly startup time and overall speed, doubting it would be suitable for production applications. Some suggested alternative approaches for achieving similar functionality, like using a server-rendered backend with a JavaScript frontend framework. Others questioned the use cases, wondering if the complexity was worth the effort compared to established approaches. Several commenters pointed to the large size of the Wasm bundle as a major drawback. A few expressed cautious optimism, acknowledging the technical achievement while remaining unsure of its real-world applicability. Finally, some highlighted the potential benefits for specific niches, such as online code editors or interactive tutorials.
The Hacker News post titled "Now you can run Ruby on Rails in the browser using WebAssembly" (linking to a web.dev article about the same) generated a moderate amount of discussion, with a mixture of excitement, skepticism, and practical considerations.
Several commenters expressed enthusiasm about the potential of running Rails entirely in the browser, highlighting benefits like simplified deployment, offline capabilities, and improved collaboration. One user envisioned a future where complex web applications could be shared seamlessly via URL, much like sharing a document, with the entire application logic and data bundled within the browser. Another commenter pointed out the potential for streamlined development workflows, eliminating the need for separate backend and frontend deployments.
However, many comments also raised concerns and limitations. Performance was a recurring theme, with some users questioning whether WebAssembly could truly deliver a smooth experience for a complex framework like Rails. The size of the compiled Wasm bundle was also mentioned as a potential obstacle, especially for larger applications. One commenter humorously pointed out the irony of returning to the "download the entire internet" model of early web pages.
Several users discussed the practical implications of running Rails in the browser, particularly regarding database access. Questions arose about how data persistence would be handled, with suggestions including using IndexedDB or relying on a separate backend server for data storage. The security implications of running server-side code within the client's browser were also raised, with concerns about potential vulnerabilities and the need for robust security measures.
Some comments focused on specific technical details, such as the use of the WASI (WebAssembly System Interface) and its implications for portability. One commenter questioned the choice of Ruby as the initial target language for this technology, suggesting that other languages might be better suited for WebAssembly due to their smaller runtime size.
Finally, several commenters shared their own experiences with similar technologies, such as using Python in the browser via WebAssembly. These comments provided valuable context and insights into the challenges and opportunities of bringing server-side frameworks to the client-side. Overall, the comments reflected a cautious optimism about the potential of running Rails in the browser, acknowledging the exciting possibilities while also recognizing the significant hurdles that need to be overcome.