Logo
Back to Blog
Development August 12, 2026 8 min read

How to Prepare Web Content for an LLM Without Wasting Context

O

OmniWebKit Team

Web Tooling

Share:
Article Cover Image

You paste a page into a chat window and the model answers about the cookie banner. Half your context went on navigation, scripts and class names. The article you wanted it to read got truncated somewhere around the footer.

How to Prepare Web Content for an LLM

Strip what carries no meaning, keep what carries structure. That single rule covers most of the work.

Raw HTML fails on both counts. Class names, wrapper divs and inline styles consume tokens and mean nothing to a model. Meanwhile the structure that does matter — where a section starts, which items form a list — survives conversion at almost no cost.

The order we use: convert to markdown, drop navigation and footers, remove links and images unless they earn their place, then check the size before pasting anything.

Worth measuring rather than assuming. Convert one of your own pages both ways and compare the character counts. The ratio varies enormously between a text-heavy article and a marketing page, and published averages will not match your case.

Markdown vs HTML for AI — What Each Costs

Markdown keeps the structure at a fraction of the size.

Compare the same heading three ways. In HTML: <h2 class="section-title">Pricing</h2>. In plain text: Pricing. In markdown: ## Pricing.

The markdown version costs two characters more than plain text and tells the model a section began. The HTML version costs far more and adds a class name nobody needs.

Lists show the same pattern more starkly. Plain text turns a six-item list into a paragraph, and the model has to infer that six separate things were listed. A markdown hyphen makes it explicit.

Our URL to markdown converter does this in one step and reports its rough token count, so you can check the size before committing context to it.

Building a Token Budget That Holds

Decide the ceiling before you extract, not after the context fills.

Three things compete for the same space: the content, your instructions, and the model's reply. Filling the window with content leaves nothing for the answer, which is a failure people rediscover repeatedly.

Where the savings are, roughly in order:

  • Navigation and footers. The largest single cut on most pages, and pure noise.
  • Links. Substantial on documentation. A model cannot follow them.
  • Images. A long CDN URL for information the model cannot see.
  • Repeated boilerplate. Cookie notices and legal footers, repeated across every page you feed it.

Keep tables. Flattening one into prose reliably confuses a model about which value belongs to which column, and the markdown version costs very little.

Any character-based token estimate is approximate, including ours. Dividing by four suits English prose and misleads on code or non-Latin scripts.

RAG Content Extraction and Where Chunking Goes Wrong

Split on headings, not on character count. This is the highest-value change most retrieval systems can make.

Cutting every thousand characters slices through the middle of sections. A chunk starts halfway into one topic and ends halfway into another, so neither is retrievable properly and both look partly relevant to everything.

Splitting on structure gives you chunks that are already about one thing. That is why converting to markdown first is worth doing even when a model never sees the markdown — the headings tell you where the boundaries are.

Add the page title and section heading to every chunk. It costs a handful of tokens and transforms retrieval, because a chunk reading "This applies to version 3 and later" is meaningless without knowing what "this" is.

Record when you extracted it, too. Stale content is worse than missing content — a model presents both with identical confidence.

What Stops This Working

Pages that build content with JavaScript return nothing to extract.

No conversion or chunking strategy helps when the fetch receives an empty shell. Check whether the text is in the page source before blaming your pipeline — the diagnosis is in pages that render client-side.

Permission is the other constraint, and it is easy to skip when the volume feels small. Extracting a page to read is one thing; building a retrieval corpus from someone else's content is another. Our note on permission to use what you collect covers where that shifts.

If you are on the publishing side of this, the emerging llms.txt convention is one attempt at pointing agents to clean versions of your own pages rather than leaving them to guess.

A Workflow That Holds Up

Convert, trim, check the size, chunk on headings, label every chunk.

For a single page into a chat window, the first three are enough. For a retrieval corpus, the last two are where quality actually comes from — and they are the steps most often skipped.

When you already hold the markup rather than a URL, strip markup before you paste it in without any fetch involved. And when the goal is a document to keep rather than context to spend, the full extractor gives you meta tags and images as separate groups.

Check what you captured before it reaches the model. Reading the first few lines of an extraction takes seconds and catches the cases where you captured a cookie banner instead of an article.

Frequently Asked Questions

How much context does raw HTML actually waste?

+
Enough to matter, though the ratio swings wildly by site. A content-heavy article page is mostly text; a marketing page can be mostly markup. Rather than trusting any published figure, convert one of your own pages both ways and compare — it takes a minute and the answer is specific to you.

Is markdown always better than plain text for a model?

+
When structure carries meaning, yes. Headings, lists and tables all mean something, and markdown preserves them for a few characters each. For a single flowing article with no sections, plain text is fine and marginally cheaper.

Should I strip links before sending content to a model?

+
Usually. A model cannot follow a URL, and on documentation pages inline links can be a large share of the total. Keep them when you want the output as a readable document afterwards, or when the link targets are themselves the information.

Why does my retrieval system return the wrong section?

+
Chunking on character count is the usual cause. Splitting every thousand characters cuts through the middle of sections, so a chunk starts halfway into one topic and ends halfway into the next. Split on headings instead and each chunk becomes self-contained.

Do I need to keep tables as tables?

+
Yes, and this one is worth paying tokens for. Flattening a table into prose reliably confuses a model about which value belongs to which column. A markdown pipe table keeps the relationship explicit and costs very little.

How accurate are character-based token estimates?

+
Rough. Dividing characters by four approximates English prose and nothing else. Code, markup and non-Latin scripts tokenise very differently, so treat any such figure as an order of magnitude rather than a number to plan against.

Should each chunk repeat the page title?

+
Adding the page title and section heading to every chunk costs a handful of tokens and dramatically improves retrieval. Without it, a chunk reading "This applies to version 3 and later" gives the model no idea what "this" refers to.

What about content that changes frequently?

+
Store when you extracted it and re-extract on a schedule that matches how fast it moves. Stale extracted content is worse than no content, because a model presents it with exactly the same confidence as fresh material.

Is it worth removing navigation if I have plenty of context?

+
Yes, and not mainly for the tokens. Repeated navigation across many chunks makes them look similar to a retrieval system, which degrades ranking. The noise costs you more than the space does.

Can I just paste the URL and let the model fetch it?

+
Some products do fetch, and results vary because they hit the same client-rendering wall everything else does. Extracting yourself means you can see what was actually captured before it reaches the model, which is worth the extra step for anything important.

Tags

#AI#LLM#RAG#Content