🚨 Every time you measure text in the browser… you might be slowing your app down. Yes — rendering text efficiently on the web is still a surprisingly hard problem. I recently came across an incredible library called Pretext by Cheng Lou, and it completely changed how I think about frontend performance. 💥 The problem: Every time we measure text in the browser (like height, wrapping, layout), we rely on DOM APIs like: 👉 getBoundingClientRect() 👉 offsetHeight These trigger layout reflows — one of the most expensive operations in web performance. And the worst part? We often do this repeatedly… without realizing the cost. ⚡ The solution (and why it’s genius): Instead of relying on the DOM, Pretext builds its own text layout engine — purely in JavaScript. ✔️ Measures text using the browser’s font engine (via canvas) ✔️ Precomputes and caches text structure ✔️ Uses pure arithmetic for layout (no reflow!) ✔️ Supports multiple languages, emojis, and complex scripts As described in the repo, it “side-steps the need for DOM measurements… and avoids layout reflow entirely.” 🤯 Why this is fascinating: This unlocks things that were previously messy or unreliable: • Accurate text measurement without touching the DOM • Smooth virtualization (no guessing heights) • Custom layouts like masonry, dynamic flows, canvas rendering • Preventing layout shifts before content even loads Basically — you can now treat text layout like a deterministic system, not a browser side-effect. 🧠 What I learned from this: The biggest innovations don’t always come from adding complexity… they come from rethinking the fundamentals. Instead of asking: “How do we optimize DOM measurements?” This project asks: 👉 “What if we didn’t need them at all?” ⚡ Why this matters going forward: With AI-driven UIs, dynamic content, and complex interfaces becoming the norm — we need predictable, fast, and controllable layout systems. And this feels like a step in that direction. 👇 I’ve dropped some mind-blowing demos in the comments — highly recommend checking them out. 💬 Question for you: Do you think frontend performance issues are more about bad tooling… or outdated mental models of how the browser works? #ApplicationDevelopment #JavaScript #FullStackEngineering #Performance #React #Engineering #OpenSource #TechInnovation #Programming #UI #SoftwareEngineering
Optimizing Text Layout with Pretext and JavaScript
More Relevant Posts
-
📸 "𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗶𝘃𝗲 𝗶𝗺𝗮𝗴𝗲𝘀" 𝗺𝗶𝗴𝗵𝘁 𝗯𝗲 𝗴𝗼𝗶𝗻𝗴 𝗮𝘄𝗮𝘆. Not because they failed... but because we don't need them anymore. 🧠 𝗧𝗵𝗲 𝗼𝗹𝗱 𝘄𝗮𝘆 We used: 🔹 `srcset` 🔹 `sizes` 🔹 `<picture>` To guess which image a device needed. ⚠️ 𝗧𝗵𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺 🔹 Complex markup 🔹 Multiple image versions 🔹 Hard to maintain 👉 We were solving a platform problem manually. 🚀 𝗪𝗵𝗮𝘁'𝘀 𝗰𝗵𝗮𝗻𝗴𝗶𝗻𝗴 🔹 Modern CSS (container queries, fluid layouts) 🔹 Smarter browsers 🔹 Image CDNs 👉 The platform now knows: 🔹 How big your image is 🔹 What resolution is needed 🔹 What to load 🧩 𝗧𝗵𝗲 𝘀𝗵𝗶𝗳𝘁 From: "Optimize images for devices" ➡️ to: "Let layout + browser handle it" 🧠 The real insight: Frontend evolution always follows the same pattern: 👉 We hack solutions 👉 The platform catches up 👉 Complexity disappears 🚀 The takeaway: 👉 The code you don't have to write anymore. 🔗 Source: https://lnkd.in/dwWHWCcb #Frontend #WebDevelopment #CSS #WebPerformance #UX
To view or add a comment, sign in
-
-
An engineer just tackled a UI problem we’ve been struggling with for 30+ years. Text layout. Every time a web app needs to know: “How big is this text?” It asks the browser. And the browser: • pauses execution • recalculates layout (reflow) • then returns the measurement That means it’s not just measuring text it’s recalculating the entire page. This is one of the biggest reasons behind janky scrolling and unstable UI. ⸻ Now here’s the interesting part. Pretext.js takes a completely different approach. How it works Instead of asking the DOM, it computes layout independently. 1. Uses Canvas (measureText) • Gets accurate text metrics without triggering layout 2. Splits text into segments • Handles proper word boundaries 3. Measures once and caches 4. Computes layout using pure math • line breaks • wrapping • total height No DOM reads. No reflow. No blocking. ⸻ Why this matters • Predict layout before rendering • Eliminate layout thrashing • Smooth chat apps, feeds, and virtualized lists • Better performance at scale ⸻ Reality check • Not full CSS parity yet • Requires proper font handling • Minor differences vs actual DOM rendering But the direction is important. ⸻ Takeaway We’ve been asking the browser for layout. This shows we can compute it ourselves. —— GitHub https://lnkd.in/dx7eQnUw Demo credits • Work by Cheng Lou #javascript #frontend #webdevelopment #reactjs #performance #softwareengineering #webperf #uilayout
To view or add a comment, sign in
-
The web just got a massive upgrade that nobody saw coming. Pretext is here, and it's making text rendering look like ancient technology. Jordan Walke, the mind behind React and ReasonML, just open-sourced a TypeScript library that renders text 500 times faster than the DOM. Think about that for a second. Half a millennium faster. This isn't just incremental improvement, this is a complete reimagining of how browsers handle text. Here's what makes this revolutionary: -> They trained ML models against actual browser rendering for weeks until the output perfectly matched Safari, Chrome, and Firefox. No approximations, no trade-offs. -> The demos are genuinely mind-blowing. We're talking hundreds of thousands of text boxes running at 120fps. Magazine layouts that would normally choke your browser. Chat bubbles with perfect text wrapping that just works. -> The validation is real. Engineers from Vercel, Remix, Figma, and Satian have already co-signed this. When the people building the tools you use daily get excited, you pay attention. What excites me most is the implications. At Blend, we're constantly pushing the boundaries of what's possible in web experiences. Text rendering has always been this invisible bottleneck that you just accept. Pretext removes that ceiling entirely. Imagine collaborative editors with zero lag. Design tools that handle thousands of text elements without breaking a sweat. Real-time dashboards that can actually be real-time. The performance budget you just freed up can now go toward features that matter. This is the kind of open source work that reminds you why you got into development in the first place. Not because it's flashy, but because someone looked at a fundamental constraint and said "this doesn't have to be this way." What's the first thing you'd build with 500x faster text rendering? Drop your thoughts below. WebDevelopment #OpenSource #JavaScript #DeveloperTools #TechInnovation
To view or add a comment, sign in
-
👉 aspect-ratio aspect-ratio defines the proportional relationship between width and height of an element. If either the width or height is set, the other dimension will automatically adjust to maintain the defined ratio. Syntax: aspect-ratio: width / height; Tip: Use the aspect-ratio property in responsive layouts where elements often vary in size and you want to preserve the ratio between width and height. Example: aspect-ratio: 16 / 9; 📐 How it works internally? aspect-ratio: width / height Example: 16 / 6 = 2.66 So: height = width ÷ 2.66 👉 Browser handles this automatically — no manual calculation needed. ⚠️ Important Rules • Works only if ONE dimension is auto • If both width & height are fixed → aspect-ratio ignored 📊 Why you should use it? ✔ Cleaner CSS ✔ Better performance (no JS) ✔ Fully responsive ✔ Improves UI consistency ✔ Modern browser support #CSS #FrontendDevelopment #WebDesign #UIUX #Developers #WebDev
To view or add a comment, sign in
-
-
Most developers think TailwindCSS solves UI consistency by default. The reality is that scaling a project with Tailwind requires nuanced strategies that are rarely discussed. When working on a growing app with multiple developers, inconsistent class naming sneaks in easily. One person’s `bg-blue-500` might be another’s `bg-primary`, and suddenly your UI looks unpredictable. I learned the hard way that using design tokens via Tailwind’s config for colors, font sizes, and spacing is key. It forces everyone to pick from the same palette, reducing guesswork and messy overrides. Another gotcha is purging unused styles. Large codebases with feature branches can accidentally drop needed classes if you’re not careful. We set up careful safelists and ran our builds against staging branches to catch these early. Lastly, establishing component-level style guidelines — basically “Tailwind style guides”— helped keep buttons, forms, and cards consistent without rewriting classes each time. Have you faced unexpected hurdles keeping TailwindCSS clean and consistent as your team grows? What tricks helped you save time? #TailwindCSS #WebDev #FrontendTips #CSS #DeveloperExperience #UIConsistency #TeamWorkflow #BuildTools #Tech #SoftwareDevelopment #WebDevelopment #TailwindCSS #CSSDesign #FrontendDevelopment #UIDesign #Solopreneur #DigitalFounders #ContentCreators #Intuz
To view or add a comment, sign in
-
#The "last bottleneck" in web UI just got solved. 🌐 For years, we’ve been limited by how the browser handles text. If you wanted to flow text around an image or binary-search the perfect container width, you were fighting a losing battle against performance. Cheng Lou’s new project, Pretext, is a pure JS/TS library that side-steps the DOM entirely to handle multiline text layout. Why this matters now: 1️⃣ AI-Friendly: It’s built for an era where UI needs to be dynamic and speculative. 2️⃣ Performance: It’s hundreds of times faster than traditional DOM-based measurement. 3️⃣ Freedom: We can finally build layouts (like proper masonry or custom flexbox) that CSS alone couldn't handle. The web just got a lot more flexible. Link: https://lnkd.in/gmEVTydd #Frontend #Innovation #UXDesign #ReactJS #Pretext
To view or add a comment, sign in
-
🚀 𝗕𝘂𝗶𝗹𝘁 𝗮𝗻 𝗜𝗻𝘁𝗲𝗿𝗮𝗰𝘁𝗶𝘃𝗲 𝗖𝗮𝗹𝗲𝗻𝗱𝗮𝗿 𝘄𝗶𝘁𝗵 𝗥𝗮𝗻𝗴𝗲 𝗦𝗲𝗹𝗲𝗰𝘁𝗶𝗼𝗻 & 𝗡𝗼𝘁𝗲𝘀 I recently worked on a frontend challenge where the goal was to turn a static wall calendar design into a fully interactive component — and I took it as an opportunity to focus on both functionality and product experience. 🔹 Key features: • 📅 Dynamic month navigation with smooth animations • 🎯 Date range selection (with reverse handling & hover preview) • ✍️ Notes system attached to selected date ranges • 💾 Persistent data using localStorage • 🖼 Dynamic hero images for each month • 🎨 Clean, responsive UI inspired by real wall calendars Instead of over-engineering, I focused on: → Clean architecture using custom hooks → Avoiding unnecessary state libraries (kept it simple & scalable) → Improving UX with small but impactful details 🔗 Live Demo: https://lnkd.in/gwfBCZw4 💻 GitHub: https://lnkd.in/gTPyR8zm Would love to hear your feedback! #react #frontend #javascript #webdevelopment #tailwindcss #framerMotion #uiux
To view or add a comment, sign in
-
Want to instantly elevate your website's interactivity? Add a little cursor magic. ✨ I recently built this dynamic Image Trail effect. Instead of a static page, the user's cursor leaves a fading, beautifully staggered trail of images as they navigate. It’s a fantastic way to: - Showcase portfolio pieces without cluttering the UI - Increase user engagement and time-on-page - Add a memorable, creative touch to agency or personal landing pages Building smooth, performant micro-interactions like this is what makes modern web development so exciting. What do you think of this effect? Would you use it subtly on a landing page, or go all-out for a creative portfolio? Let me know! #WebDevelopment #FrontEnd #UIUX #WebDesign #JavaScript #CreativeCoding #WebAnimation #CSS #gsap
To view or add a comment, sign in
-
𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 𝘃𝘀 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 — 𝗖𝗵𝗼𝗼𝘀𝗶𝗻𝗴 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗛𝗼𝗼𝗸 𝗮𝘁 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗧𝗶𝗺𝗲 React gives developers powerful hooks to manage side effects, but understanding when each hook runs can make a significant difference in UI performance and user experience. Two commonly misunderstood hooks are: 🔹 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁() useEffect runs after the browser has painted the UI. This makes it the right choice for: • API requests • Event listeners • Subscriptions • Logging • Updating external systems Because it runs after paint, it does not block rendering, helping keep your application fast and responsive. 🔹 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁() useLayoutEffect runs immediately after the DOM updates but before the browser paints the screen. This makes it useful for: • Reading element dimensions • Measuring layout • Scroll position adjustments • Preventing visual flicker • Synchronizing DOM changes before display Since it runs before paint, users never see intermediate layout changes. 𝗪𝗵𝘆 𝗶𝘁 𝗺𝗮𝘁𝘁𝗲𝗿𝘀 Using the wrong hook can lead to: ❌ Layout shifts ❌ Flickering UI ❌ Incorrect measurements ❌ Less predictable rendering behavior Choosing the correct hook leads to: ✅ Smoother interfaces ✅ Better visual stability ✅ More predictable components 𝗦𝗶𝗺𝗽𝗹𝗲 𝗿𝘂𝗹𝗲 𝗼𝗳 𝘁𝗵𝘂𝗺𝗯 Use useEffect → for most side effects Use useLayoutEffect → when layout or visual updates must happen before paint Small React details like this often separate working code from polished frontend engineering. #React #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Built a Contact Form UI using HTML, CSS, and JavaScript Designed a responsive Contact Us section featuring input fields for name, email, subject, and message along with a Google Maps location embed. Added a clean layout, icons for contact details, and a styled “Send Message” button for better user interaction. This frontend focuses on usability, modern design, and responsive structure. #website_of_contact_form.
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
🔥 Explore Pretext here (GitHub): https://github.com/chenglou/pretext 🚀 Some mind-blowing demos built with it: • Editorial Engine (dynamic flowing text layouts) https://somnai-dreams.github.io/pretext-demos/the-editorial-engine.html • Variable Typographic ASCII https://somnai-dreams.github.io/pretext-demos/variable-typographic-ascii.html • Shrinkwrap Showdown https://somnai-dreams.github.io/pretext-demos/shrinkwrap-showdown.html • Justification Comparison https://somnai-dreams.github.io/pretext-demos/justification-comparison.html