• Stars
    star
    5,741
  • Rank 6,713 (Top 0.2 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 5 years ago
  • Updated 8 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rich, real-time user experiences with server-rendered HTML

Phoenix LiveView

Actions Status Hex.pm Documentation

Phoenix LiveView enables rich, real-time user experiences with server-rendered HTML.

Visit the https://livebeats.fly.dev demo to see the kinds of applications you can build, or see a sneak peek below:

Phoenix.LiveView.LiveBeats.Demo.mp4

After you install Elixir on your machine, you can create your first LiveView app in two steps:

$ mix archive.install hex phx_new
$ mix phx.new demo

Feature highlights

LiveView brings a unified experience to building web applications. You no longer have to split work between client and server, across different toolings, layers, and abstractions. Instead, LiveView enriches the server with a declarative and powerful model while keeping your code closer to your data (and ultimately your source of truth):

  • Declarative rendering: Render HTML on the server over WebSockets with a declarative model, including an optional LongPolling fallback.

  • Rich templating language: Enjoy HEEx: a templating language that supports function components, slots, HTML validation, verified routes, and more.

  • Small payloads: LiveView is smart enough to track changes so it only sends what the client needs, making LiveView payloads much smaller than server-rendered HTML.

  • Live form validation: LiveView supports real-time form validation out of the box. Create rich user interfaces with features like uploads, nested inputs, and specialized recovery.

  • File uploads: Real-time file uploads with progress indicators and image previews. Process your uploads on the fly or submit them to your desired cloud service.

  • Rich integration API: Use the rich integration API to interact with the client, with phx-click, phx-focus, phx-blur, phx-submit, and phx-hook included for cases where you have to write JavaScript.

  • Optimistic updates and transitions: Perform optimistic updates and transitions with JavaScript commands via Phoenix.LiveView.JS.

  • Loose coupling: Reuse more code via stateful components with loosely-coupled templates, state, and event handling — a must for enterprise application development.

  • Live navigation: Enriched links and redirects are just more ways LiveView keeps your app light and performant. Clients load the minimum amount of content needed as users navigate around your app without any compromise in user experience.

  • Latency simulator: Emulate how slow clients will interact with your application with the latency simulator.

  • Robust test suite: Write tests with confidence alongside Phoenix LiveView built-in testing tools. No more running a whole browser alongside your tests.

Official announcements

News from the Phoenix team on LiveView:

Learning

See our existing comprehensive docs and guides for more information.

Installation

LiveView is included by default in all new Phoenix v1.6+ applications and later. If you have an older existing Phoenix app and you wish to add LiveView, see the installation guide on HexDocs.

What makes LiveView unique?

LiveView is server-centric. You no longer have to worry about managing both client and server to keep things in sync. LiveView automatically updates the client as changes happen on the server.

LiveView is first rendered statically as part of regular HTTP requests, which provides quick times for "First Meaningful Paint", in addition to helping search and indexing engines.

Then LiveView uses a persistent connection between client and server. This allows LiveView applications to react faster to user events as there is less work to be done and less data to be sent compared to stateless requests that have to authenticate, decode, load, and encode data on every request.

When LiveView was first announced, many developers from different backgrounds got inspired by the potential unlocked by LiveView to build rich, real-time user experiences. We believe LiveView is built on top of a solid foundation that makes LiveView hard to replicate anywhere else:

  • LiveView is built on top of the Elixir programming language and functional programming, which provides a great model for reasoning about your code and how your LiveView changes over time.

  • By building on top of a scalable platform, LiveView scales well vertically (from small to large instances) and horizontally (by adding more instances). This allows you to continue shipping features when more and more users join your application, instead of dealing with performance issues.

  • LiveView applications are distributed and real-time. A LiveView app can push events to users as those events happen anywhere in the system. Do you want to notify a user that their best friend just connected? This is easily done without a single line of custom JavaScript and with no extra external dependencies (no extra databases, no Redis, no extra message queues, etc.).

  • LiveView performs change tracking: whenever you change a value on the server, LiveView will send to the client only the values that changed, drastically reducing the latency and the amount of data sent over the wire. This is achievable thanks to Elixir's immutability and its ability to treat code as data.

Browser Support

All current Chrome, Safari, Firefox, and MS Edge are supported. IE11 support is available with the following polyfills:

$ npm install --save --prefix assets mdn-polyfills url-search-params-polyfill formdata-polyfill child-replace-with-polyfill classlist-polyfill new-event-polyfill @webcomponents/template shim-keyboard-event-key core-js

Note: The shim-keyboard-event-key polyfill is also required for MS Edge 12-18.

Note: The event-submitter-polyfill package is also required for MS Edge 12-80 & Safari < 15.4.

// assets/js/app.js
import "mdn-polyfills/Object.assign"
import "mdn-polyfills/CustomEvent"
import "mdn-polyfills/String.prototype.startsWith"
import "mdn-polyfills/Array.from"
import "mdn-polyfills/Array.prototype.find"
import "mdn-polyfills/Array.prototype.some"
import "mdn-polyfills/NodeList.prototype.forEach"
import "mdn-polyfills/Element.prototype.closest"
import "mdn-polyfills/Element.prototype.matches"
import "mdn-polyfills/Node.prototype.remove"
import "child-replace-with-polyfill"
import "url-search-params-polyfill"
import "formdata-polyfill"
import "classlist-polyfill"
import "new-event-polyfill"
import "@webcomponents/template"
import "shim-keyboard-event-key"
import "event-submitter-polyfill"
import "core-js/features/set"
import "core-js/features/url"

import {Socket} from "phoenix"
import {LiveSocket} from "phoenix_live_view"
...

Contributing

We appreciate any contribution to LiveView.

Please see the Phoenix Code of Conduct and Contributing guides.

Running the Elixir tests:

$ mix deps.get
$ mix test

Running the Javascript tests:

$ cd assets
$ npm run test
# to automatically run tests for files that have been changed
$ npm run test.watch

JS contributions are very welcome, but please do not include an updated priv/static/phoenix_live_view.js in pull requests. The maintainers will update it as part of the release process.

More Repositories

1

phoenix

Peace of mind from prototype to production
Elixir
20,545
star
2

phoenix_live_dashboard

Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Elixir
1,925
star
3

phoenix_pubsub

Distributed PubSub and Presence platform for the Phoenix Framework
Elixir
611
star
4

flame

Elixir
607
star
5

phoenix_guides

User guides for the Phoenix web development framework.
499
star
6

tailwind

An installer for tailwind
Elixir
461
star
7

phoenix_ecto

Phoenix and Ecto integration with support for concurrent acceptance testing
Elixir
437
star
8

phoenix_html

Building blocks for working with HTML in Phoenix
Elixir
379
star
9

phoenix_live_reload

Provides live-reload functionality for Phoenix
Elixir
289
star
10

firenest

Elixir
271
star
11

esbuild

An installer for esbuild
Elixir
261
star
12

phoenix_pubsub_redis

The Redis PubSub adapter for the Phoenix framework
Elixir
174
star
13

dns_cluster

Simple DNS clustering for distributed Elixir nodes
Elixir
162
star
14

vscode-phoenix

Syntax highlighting support for Phoenix templates in Visual Studio Code.
155
star
15

plds

CLI version of Phoenix LiveDashboard
Elixir
85
star
16

websock

A specification for Elixir apps to service WebSocket connections
Elixir
70
star
17

phoenix_view

View abstraction for Phoenix v1.0-v1.6
Elixir
64
star
18

tree-sitter-heex

HEEx grammer for Tree-sitter
JavaScript
48
star
19

phoenix_template

Template rendering for Phoenix
Elixir
48
star
20

ex_conf

Simple Elixir Configuration Management
Elixir
35
star
21

archives

Holds archives for released Phoenix versions
27
star
22

websock_adapter

Implementation of the WebSock specification for servers
Elixir
25
star
23

phoenix_site

CSS
13
star
24

phoenix_html_helpers

Collection of helpers to generate and manipulate HTML contents
Elixir
13
star
25

media

Phoenix Related Media
10
star
26

node_checker

Elixir
3
star