Pretext.js

Pretext.js – Textmessung ohne DOM-Berührung

Einführung

Pretext.js: Reine JavaScript-Textmessung ohne DOM-Zugriffe oder Reflow. Blitzschnell für Virtual Scrolling, AI-Chats, mehrzeiligen Text. TypeScript-first, multilingual, 0 DOM-Reads.


Aktualisiert am:

2. Apr. 2026

Monatliche Besucher:

SimilarWeb Icon
--

Partnerprogramm:

No

Pretext.js's Übersicht

Pretext.js is a pure JavaScript and TypeScript-first library for fast text measurement and layout without touching the DOM. It eliminates forced synchronous reflows by using Canvas for one-time glyph measurements via prepare(), followed by instant pure arithmetic layouts with layout(). Achieving ~2ms for 1,000 blocks, it supports 12+ writing systems including CJK, Arabic, Hebrew, Thai, Hindi, and Korean. Zero runtime dependencies, real font metrics, reusable handles for multiple widths. Perfect for virtual scrolling, AI chat bubbles, multilingual feeds, and performance-critical text-heavy UIs. 14k+ GitHub stars.


Pretext.js's Eigenschaften

  • Zero DOM reads after prepare()

  • Real font metrics via Canvas measureText()

  • Multilingual support for 12+ writing systems

  • TypeScript-first with full types

  • Reusable prepared handles for multiple container widths

  • Zero runtime dependencies

  • Pure arithmetic layout for instant results

  • Accurate line breaking and bidirectional text


Pretext.js's FRAGEN UND ANTWORTEN


Pretext.js's Pro und Kontra

Profis

  • Blazing fast: 500x faster than DOM reflows, ~2ms for 1000 blocks
  • Accurate real browser font metrics
  • Production-ready multilingual support
  • Zero dependencies, small bundle size
  • Excellent TypeScript integration

Nachteile

  • Requires initial Canvas-based prepare() call
  • Focused on height/lineCount, not full DOM positioning
  • Dependent on browser Canvas API availability
  • Learning curve for prepare/layout workflow
  • Limited to text measurement, not styling or rendering

Pretext.js's Anwendungsfälle

  • Variable-height virtual scrolling for 10,000+ items
  • Pre-computing heights for AI chat bubbles in streaming responses
  • Multilingual content feeds mixing scripts like Chinese, Arabic, Korean
  • Performance-critical text-heavy UIs like code editors or social feeds

Pretext.js's Zielpublikum

  • Frontend developers optimizing performance
  • React and framework-agnostic UI builders
  • i18n and multilingual app developers
  • Virtual list and infinite scroll implementers
  • AI chat interface creators

Pretext.js's Preisgestaltung

Free open-source library published on npm with zero runtime dependencies. No paid tiers or subscriptions mentioned.

Pretext.js's Alternativen