A lightweight userscript that keeps long ChatGPT conversations fast and responsive by automatically pruning the DOM.
Designed for engineers, power users, and anyone who works inside very long AI chats containing logs, code, and large responses.
ChatGPT runs as a Single Page Application (SPA).
When a conversation grows large, the browser must maintain thousands of DOM nodes, which leads to:
- scroll lag
- layout recalculations
- increased memory usage
- GPU/CPU spikes
- occasional UI freezes
This script solves the problem by applying a hybrid pruning strategy.
The script continuously monitors the DOM and organizes conversation turns into three zones:
The newest messages remain untouched for maximum readability.
Older messages are hidden using modern browser rendering optimizations:
content-visibility- layout containment
- reduced paint cost
This dramatically improves scroll performance without breaking React reconciliation.
Very old messages are deleted to prevent DOM bloat.
- Automatic DOM pruning via
MutationObserver - Hybrid collapse + delete strategy
- Removes empty conversation turns
- Toggle button (
PRUNE ON / OFF) - Scroll position preservation
- Low CPU overhead (no polling)
- React-safe approach
- Zero dependencies
Paste the script and save.
You should see a PRUNE ON button in the bottom-right corner.
Inside the script:
const CFG = {
keepFull: 80, // newest turns kept fully visible
keepSoft: 200, // turns between keepFull and keepSoft are collapsed
};This script intentionally avoids aggressive DOM mutations that could destabilize React. All operations are strictly visual. It does not:
- Intercept network traffic.
- Modify ChatGPT data.
- Access prompts.
- Inject external code.
- Deleted messages cannot be restored without reloading the conversation.
- Browser search does not see collapsed content.
- Extremely aggressive thresholds may cause minor scroll shifts.
keepFull: 60–100
keepSoft: 150–300
keepFull: 40–60
keepSoft: 120–180