惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
S
SegmentFault 最新的问题
Jina AI
Jina AI
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
B
Blog
博客园 - 【当耐特】
博客园 - Franky
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I was burning context feeding HTML to LLMs, so I built a ...
Konstantin Konstantinov · 2026-06-26 · via DEV Community

If you build AI agents, scrapers, or RAG pipelines, you have run into this: feeding raw HTML to a model is mostly waste. The <div>, the class="...", the nav, the cookie banner. None of it is the content you wanted, and all of it costs tokens.

I knew this was inefficient. I did not appreciate how inefficient until I measured it. Here is a single page of GitHub's documentation, run through an audit:

           HTML            Markdown        Savings
───────────────────────────────────────────────────
Tokens     138,550         9,364           -93.2%
Chars      554,200         37,456          -93.2%
Words      27,123          4,044
Size       541.3 KB        36.6 KB         -93.2%

Ninety-three per cent of the tokens, gone, with no loss of meaning. The intuition is simple: <h2>About Us</h2> carries the same information as ## About Us and costs several times more to read. Multiply that across a real page and the boilerplate is most of your payload. Across a scraping or RAG workload, that is the difference between a cost model that works and one that does not.

What was already out there

Before writing anything, I looked at the options.

Heavy scrapers. Spinning up Puppeteer or Cheerio to strip HTML works, but it drags a headless browser and a pile of dependencies into a project that may not want either.

Cloudflare's Markdown for Agents. Cloudflare ships exactly this conversion at the edge, and it is genuinely good. It is also free on their paid plans, so if your site already sits behind Cloudflare, you may not need anything else. The catch is in the requirement itself: it only helps if your traffic runs through Cloudflare. I wanted something that lived in my own code, ran anywhere, and did not assume a particular network sat in front of it. The library credits Cloudflare's work as the inspiration, because that is where the idea came from.

What I actually wanted was a small, framework-agnostic way to serve Markdown whenever an agent asked for it, with nothing else attached.

markdown-for-agents

The mechanism is content negotiation, the boring HTTP feature that turns out to be exactly right for this. A normal browser visits your site and gets HTML. An agent visits with Accept: text/markdown, and the middleware intercepts the request, strips the boilerplate, and returns clean Markdown from the same URL. No second endpoint, no separate build, no fork in your routing.

import { convert } from 'markdown-for-agents';

const { markdown, tokenEstimate } = convert(html, { extract: true });

The design goals, in order:

One dependency. The core relies on a single HTML parser and nothing else. No headless browser, no DOM.

Runs anywhere. Node, Bun, Deno, Cloudflare Workers, Vercel Edge, the browser. If it speaks Web Standards, it works.

The same idea in Python. There is a zero-dependency Python package alongside the TypeScript one, with middleware for FastAPI, Flask, and Django. Half the RAG and scraping world lives in Python, and I did not want to leave it out.

Drop-in middleware. Express, Fastify, Hono, Next.js, and any Web Standard server. The middleware reads the Accept header, passes normal browser traffic through untouched, and converts only when an agent asks.

Try it without installing anything

Point the audit tool at any URL and see what you would save:

npx @markdown-for-agents/audit https://docs.github.com/en/copilot/get-started/quickstart

Or paste a URL or raw HTML into the playground and watch the conversion happen live:

https://markdown-for-agents.vercel.app/playground

Why I open-sourced it

I built it because I wanted my own websites to be prepared and agent-friendly, and I was seeing my own usage limits get burned by HTML-only websites. If you are dealing with context limits or token costs from web content, it might save you the same.

The code is here: https://github.com/KKonstantinov/markdown-for-agents``