Html Over the Wire: A New Web Development Approach

Author

Reads 1.1K

Flock of Birds on Utility Post
Credit: pexels.com, Flock of Birds on Utility Post

Html Over the Wire is a game-changer for web development, allowing developers to create web applications without the need for a traditional server-client architecture.

This approach uses a protocol called WebSockets to establish a persistent, bi-directional communication channel between the client and server, enabling real-time data transfer.

Html Over the Wire eliminates the need for polling, reducing the amount of data transferred and improving overall performance.

By leveraging WebSockets, developers can create more efficient and scalable web applications, reducing the load on servers and improving user experience.

Hotwire Frameworks

Livewire is a full-stack framework for Laravel that makes building dynamic interfaces simple. It renders the initial output with the page, making it SEO friendly.

Livewire makes AJAX requests to the server with updated data, allowing for efficient communication between the client and server.

The server re-renders the component and responds with the new HTML, which Livewire then uses to intelligently mutate the DOM.

Phoenix and Turbo

Credit: youtube.com, Workshop: Hotwire: HTML over The Wire

Phoenix and Turbo are two popular tools in the HTML over the wire world. Phoenix is a HTTP client library that allows you to send HTTP requests and receive responses.

In Phoenix, you can use the `request` method to send a GET request to a server. For example, `client.request('GET', 'http://example.com')` would send a GET request to the specified URL.

Turbo, on the other hand, is a library that allows you to send HTTP requests and receive responses in a more concise way. With Turbo, you can use the `get` method to send a GET request, like this: `Turbo.get('http://example.com')`.

Readers also liked: Html Canvas Javascript Library

Phoenix LiveView

Phoenix LiveView is a game-changer for building real-time user experiences. It enables server-rendered HTML with WebSockets and optional LongPolling fallback.

With LiveView, you can send only what changed to the client, skipping template markup and reducing the payload. This makes it perfect for large applications where code reusability is essential.

You can reuse code via components, breaking templates, state, and event handling into reusable bits. This is a huge time-saver and makes development much more efficient.

On a similar theme: Html B Tag

Credit: youtube.com, Build a real-time Twitter clone in 15 minutes with LiveView and Phoenix 1.5

LiveView comes with a latency simulator, allowing you to emulate how slow clients will interact with your application. This is a huge help when testing and debugging your application.

It also includes a bunch of testing tools that make it easy to write a confident test suite without the complexity of running a whole browser alongside your tests.

If this caught your attention, see: Html Application

Spring Boot and Server-Sent Events

Spring Boot can handle Server-Sent Events (SSE) in addition to WebSockets and Turbo Streams.

Using SSE is a good approach, especially when HTTP/2 is available, as it eliminates the need for WebSockets.

This was demonstrated in a sample where a stream of average system load was generated every 3 seconds.

A controller was created to read the stream and map it to a Turbo Stream document as an Event Stream response.

The controller used Thymeleaf integration with WebFlux / Reactor Core to wrap a stream of values in a ReactiveDataDriverContextVariable.

This allowed the template to be returned as an Event Stream, with each flush of the data-driven buffer resulting in a response being sent to the browser.

Explore further: Response in Html

Kotlin/Java Spring Boot Sample

Credit: youtube.com, Spring Boot Server Sent Events Example | Unidirectional Streams | Tech Primers

In a Kotlin/Java Spring Boot sample, we can create a simple server that sends events to clients.

To send events, we use the Spring @RestController annotation to create a controller that handles HTTP requests and returns responses.

The controller method returns a Flux of Event objects, which are sent to the client as Server-Sent Events.

We can also use the Spring @ServerSentEvent annotation to send events to the client.

This annotation is used in conjunction with the @RestController annotation to create a server that sends events to the client.

In a Spring Boot application, we can use the Spring Boot Actuator to monitor the health of the server and detect any issues.

The Spring Boot Actuator provides a set of endpoints that can be used to monitor the server's health and detect any issues.

We can also use the Spring Boot DevTools to quickly restart the server and see the effects of changes to the code.

The Spring Boot DevTools provide a set of features that make it easy to develop and test Spring Boot applications.

Take a look at this: Is Html Still Used

Server Sent Events

Credit: youtube.com, Server-Sent Events vs WebSockets | System Design

Server-Sent Events are a great way to push updates to a web page without the need for user interaction. They're supported by modern browsers and can be used in conjunction with WebSockets and HTTP/2.

One of the challenges with WebSockets is their limited adoption over WAN connections. However, with HTTP/2 and Server-Sent Events, there are few compelling reasons to use WebSockets anymore.

To use Server-Sent Events with Turbo Streams, you'll need to create a controller that reads a stream of data and maps it to a Turbo Stream document as an Event Stream response. This can be done using a library like Thymeleaf with WebFlux/Reactor Core.

In our example, we used Thymeleaf to wrap a stream of values in a ReactiveDataDriverContextVariable for the model to use during interpolation into the template. This allows us to return the template as an Event Stream, with each flush of the data-driven buffer resulting in a response being sent to the browser.

If this caught your attention, see: Html Event

Credit: youtube.com, Server-sent events are pretty cool

Here are some key facts about Server-Sent Events and Turbo Streams:

  • Server-Sent Events are supported by modern browsers and can be used in conjunction with WebSockets and HTTP/2.
  • With HTTP/2 and Server-Sent Events, there are few compelling reasons to use WebSockets anymore.
  • Thymeleaf can be used to wrap a stream of values in a ReactiveDataDriverContextVariable for the model to use during interpolation into the template.
  • Each flush of the data-driven buffer results in a response being sent to the browser.

By using Server-Sent Events with Turbo Streams, you can create a seamless and efficient user experience, updating parts of a page without the need for user interaction.

Hotwire Overview

Hotwire is based on rendering HTML on the server in the traditional Ruby on Rails way, hence the name HTML over the wire.

It's a great approach to build modern web applications without loading the application with much JavaScript code. Hotwire promotes easy application design by keeping the client-side code uncomplicated.

Hotwire consists of two main parts: Turbo and stimulus. The most interesting part is Turbo, which dynamically updates parts of a page without having to write JavaScript.

Turbo is used 80% of the time to implement interactivity on a web page, but there are cases where you'll need to write your own JavaScript code.

You might enjoy: Html List without Bullets

Html Over the Wire

You can build a quick solution with a minimum framework using HTML, perfect for pre-sales interactive prototypes, proof-of-concepts, tutorials, or online utilities. This approach is ideal for projects that require a fast turnaround and minimal learning curve.

Credit: youtube.com, FunctionalFest • "HTML over the wire" meets Functional Programming • Marco Sampellegrini

If you're already familiar with HTML, you can focus on the visual aesthetic interaction without investing in asynchronous server communication. JavaScript can be sprinkled in to address edge cases, such as low-level browser APIs like local storage or Web Audio.

HTMX allows you to provide a complete single-page web app experience, but you may need to add some vanilla JS to handle edge cases. There are also several JS frameworks that share the Low Code HTML-first minimalist HTMX philosophy, including AlpineJS, Django Sockpuppet, and HTMX itself.

The Neodigm 55 Heatmap component uses the Intersection Observer pattern to track visible block elements, and it's configured to only report if a card is visible for more than 3 seconds. This threshold is configurable, but there may be edge cases where data loses fidelity, such as when the user opens another tab or abruptly closes the browser.

Take a look at this: Html Visible

For another approach, see: Golang Wire

Danny Orlandini

Writer

Danny Orlandini is a passionate writer, known for his engaging and thought-provoking blog posts. He has been writing for several years and has developed a unique voice that resonates with readers from all walks of life. Danny's love for words and storytelling is evident in every piece he creates.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.