百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

ts-liveview

> 前端框架
开源

使用 TypeScript 构建混合 SSG 和 SSR 实时 SPA/MPA

198 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 TypeScript 构建混合 SSG 和 SSR 实时 SPA/MPA

ts-liveview

Build hybrid SSG and SSR realtime SPA/MPA with Typescript

ts-liveview helps to deliver fast and interactive user interface directly from node.js server.

(Without MBs of javascript to be downloaded and executed on the client side.)

The client-side runtime of ts-liveview is below 13KB (2.3KB bundled, minified and gzipped).

ts-liveview supports JSX but it doesn't rely on Virtual DOM. Instead, precise DOM operations are derived from application-specific event handlers, and sent to the browser client(s) for realtime UI updates.

简体中文 | 繁體中文

Get Started

To create a new project, run:

bash
## start from a template
npm init ts-liveview my-app
# or "npx create-ts-liveview@latest my-app" for latest version

cd my-app

## install packages and setup sqlite database
./scripts/init.sh

## starts the development server
npm start

To setup a cloned project, run ./scripts/init.sh, which will install packages and setup sqlite database for you.

To update database schema, see db/README.md

To deploy, setup scripts/config then run ./scripts/deploy.sh, which will build and deploy the server with knex migrate and pm2.

To test https-required functions during development (e.g., camera, microphone):

  1. Install caddy: ./scripts/caddy-install.sh (Mac/Linux) or ./scripts/caddy-install.ps1 (Windows)
  2. Enable the caddy https proxy in .env file: CADDY_PROXY=enable

Details refer to create-ts-liveview

For team onboarding and detailed patterns, see docs/developer-guide.md. To configure how AI assistants (e.g. Cursor) should behave when editing code, see docs/ai-agent-guidelines.md.

To keep track of tasks, you may log them in tasks/*.md so they aren't lost while you design, implement, review, and commit — run ./scripts/new-task.sh to create one, or you may use your preferred IDE/cli/AI assistant to create the files.

Configuration

  • Environment variables: .env (see .env.example and server/env.ts)
  • Site settings: server/config.ts
  • Database: SQLite with better-sqlite3-proxy and knex migrations — included and usable out of the box. No ORM (Prisma, Drizzle, etc.) or other database needed unless you choose to modify. See db/README.md.
  • PWA : Working setup included.
    • Manifests — Generated by server/app/manifest.ts into public/pwa/. Edit manifest.ts for names, orientation, colors, icon paths; colors also fill the HTML theme meta.
    • Icons — replace icon files in the public directory: icon-192.png, icon-512.png, favicon.ico, apple-touch-icon.png.
    • Tip: You can use App Store Images — a simple single-file HTML webapp that generates PWA and app-store icons from one image. (Source)

Available npm scripts

npm start: Start the development server, with realtime-update and live-reload.

npm run build: Compile the typescript server into 'dist' folder, and bundle the client into 'build' folder. This step is only needed when preparing production deployment.

npm run fix: Auto add .js extension in import paths, which is required in esm runtime.

npm run format: Auto format the source code with prettier.

npm run lint: Lint the codebase with eslint and apply auto fix if possible.

npm run size: Build the frontend and check the size of bundled, minified, and gzipped versions respectively.

VSCode/Cursor: Ctrl+Shift+P → "Run Build Task", which auto runs dev server + type-check in two terminal windows (config in .vscode/tasks.json).

Features

  • Support hybrid rendering mode
    • Boot-time pre-rendering [1]
    • Request-time server-rendering with HTML streaming [2]
    • Run-time live update [3]
  • Support url-based routing architectures
    • Multi-Page Application (MPA)
    • Single-Page Application (SPA) [4]
    • Hybrid of SPA and MPA
    • Write UI and API routing once in one place
    • Nested routing
    • Sync / async routes
    • Static / dynamic document title and description meta
    • Type-Safe routing with inferred static type checking
  • Follow the DOM convention
    • class, style, onclick e.t.c. are string attributes, with helper functions to convert from objects
    • Compatible with css frameworks and web components (doesn't require framework specific wrappers unlike react)
    • Support inline script and Immediately Invoked Function Expression (IIFE)
  • Enable interactive UI with minimal amount of javascript to be downloaded
  • Load only what you need, when you need it
    • Built-in libraries:
      • image compression (preview & upload)
      • sweetalert (unrestricted)
      • swiper (slides / images carousel)
      • chart.js (canvas based line chart, bar chart, and more)
      • canvas-confetti (fireworks animation)
      • DataTables (pagination / search)
    • Custom client-side code:
      • Simple code: use JavaScript inline within pages
      • Organized code: use TypeScript modules for type checking
  • Still functional when javascript is disabled on client device with links and forms [5]
  • Support to develop with JSX, AST, component, or html template
  • Error boundary for each component [6]
  • Code Minification
    • Minify CSS & JS with esbuild
    • Minify HTML fragment with AST converter
    • Minify in production mode, skip in development mode
    • Memorized to speed up
    • Allow skipping minimization for dynamic and short code
  • Efficient wire format
  • Lightweight WebSocket-based protocols [7]
  • Reliable connection
    • Auto reconnect when network resume
    • Auto send accumulated offline messages when network resume (WIP)
  • Work well with express.js [8]
  • Built-in locale support (language and timezone)
  • CSRF protection via SameSite=Lax cookies (in auth templates)
  • Multi-dimensional rate limiting with token bucket algorithm (IP, user, target, global)
  • Fully customizable [9]
  • Working PWA setup — see Configuration
  • Multiple starter templates
    • v5-demo (kitchen sink demos)
    • v5-minimal-template (single page starter)
    • v5-minimal-without-db-template
    • v5-web-template (mobile-responsive webapp)
    • v5-ionic-template (mobile-first webapp)
    • v5-hybrid-template (switchable between of web and ionic template)
    • v5-auth-template (extends hybrid-template with user login/register and email verification and protected routes)
    • v5-auth-web-template (responsive web version auth template)
    • v5-auth-ionic-template (mobile-first version auth template)

Remarks:

[1] Pay the AST-to-HTML conversion time-cost once at boot-time instead of at each request-time

[2] Response contentful html page directly to GET request. Content chunk is streamed to clients as soon as it's ready, without waiting for client-side javascript bundles nor data requests to start rendering.

[3] Updates can be triggered by (bi-directional) events from the server or other clients

[4] With history.pushState() and PopStateEvent

[5] For screen-reader, text-based browser, and people with slow or unstable network, or simply tried with privacy invading scripts

[6] Each function component are evaluated with error handling, this approach can deliver as much as possible, avoiding blank pages when error occur.

[7] The network client code is 0.4K to 0.9K minified, 102x to 45x smaller than socket.io.min.js

[8] The entry point of ts-liveview app can be wrapped as an express middleware

[9] ts-liveview is provided as a template (rather than a library), hence any part can be modified to suit your need

Custom Client-Side Code for Complex Interactions

While ts-liveview is designed for a server-centric experience, it doesn't limit you to simple interactions. For client-side logic, you have two approaches:

Simple code: Write JavaScript inline within your pages for quick, direct functionality.

Organized code: Use TypeScript modules for more complex flows where type checking helps maintain code quality. Load them via the loadClientPlugin function, which allows you to:

  • Write code in TypeScript (instead of JavaScript strings inline)
  • Import other files and npm packages
  • Bundle code specifically for that page

The bundle is only loaded on pages that use it, so initial loading times for other pages remain fast.

Concrete Examples:

  • Canvas Animations: Use canvas-confetti for interactive fireworks and particle effects
  • Rich UI Components: Integrate sweetalert2 for advanced modal dialogs and notifications
  • Real-time Media Processing: Build custom AI-powered features like:
    • MediaPipe for real-time face landmark detection, hand tracking, and gesture recognition
    • TensorFlow.js for on-device machine learning inference
    • WebRTC for live video streaming with real-time analysis
    • Canvas-based rendering for custom visualizations and games

See the Client-Side Library Integrations Demo for examples of third-party library integrations and the TypeScript Page Demo for complex custom features like camera streams and AI models.

Size Comparison with other tools

Tools Runtime Code Size (minified)
Vanilla 0.3K
ts-liveview 4 6.5K OR same size as vanilla
Stencil 2.0.1 13.7K
Svelte 3.0.0 17.4K
Vue 3.2.33 49.3K
React 17.0.2 144.6K
Angular 13.3.0 155.8K

Remark: Size of other tools taking reference from https://github.com/beenotung/spa-state-demo

Q & A

Why server-rendered?

  • To deliver initial meaningful paint as soon as possible (response contentful HTML to HTTP GET request, not just skeleton demanding further script and ajax request)

  • To avoid over-bloating the amount of javascript needed to download and execute by the client browser

  • Enable server-driven feature flags, the client only downloads relevant content of the current page

  • To allow 'over-the-air' updates of application state and deployment

Why HTML Streaming?

HTML Streaming enables progressive rendering. The server sends html chunks as soon as they're ready. The browser, on the other side, progressively receives and renders the content. As a result, the content will be visible to users earlier.

Below simulation from marko illustrates the visual difference with/without html streaming. In the example, both sides take the same amount of time to finish rendering. However, the right-hand-side example using html streaming shows the contents progressively, allowing the user to start reading earlier.

  Illustration captured by
  Taylor Hunt
  from
  markojs.com/#streaming

Despite the response body is sent with streaming, the document title and meta description can be generated dynamically according to routing result. Details see the Thermostat and routing demo.

Why JSX?

Previous versions of ts-liveview use [template string](https://github.com/beenotung/ts-liveview/blob/25f5

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScripthtml-streamingliveviewrealtime-applicationserver-side-rendering

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架