dom-manipulation-best-practices

dom-manipulation-best-practices is a cursor rule for Cursor from adobecom/express-milo. It costs 2,921 tokens per session, scanned A, a copy of dom-manipulation-best-practices, Apache-2.0.

A set of rules for creating and enhancing webpage elements in stages, keeping the first visible content simple and fast to insert.

In plain words
What is it for?
Use it when building or changing page elements, especially first-section content that affects Largest Contentful Paint and enhancements added after the initial load.
Why use it?
It reduces the amount of page structure and JavaScript work needed before the main content can appear, while postponing extra enhancements.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/adobecom/express-milo/dom-manipulation-best-practices
Clone the repo
git clone --depth 1 https://github.com/adobecom/express-milo

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dom-manipulation-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/rules/adobecom/express-milo/dom-manipulation-best-practices.svg)](https://agentmods.dev/rules/adobecom/express-milo/dom-manipulation-best-practices)
Your own site
<a href="https://agentmods.dev/rules/adobecom/express-milo/dom-manipulation-best-practices"><img src="https://agentmods.dev/badge/rules/adobecom/express-milo/dom-manipulation-best-practices.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,921 This file is loaded in full into every session.
When invoked 2,921 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin 100% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.02921 $0.02921
Opus 5 $0.01460 $0.01460
Sonnet 5 $0.00584 $0.00584
Haiku 4.5 $0.00292 $0.00292

Measured 6d ago against content hash d8aad088f48d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

dom-manipulation-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

100% identical to dom-manipulation-best-practices — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.cursor/rules/dom-manipulation-best-practices.mdc · 449 lines

How it starts

The opening of the file, as written. The whole thing — 449 lines — stays where its author put it; the contents beside it link to each section on GitHub.

DOM Manipulation Performance Rules - Three-Phase Strategy

APPLY: EVERY QUERY - CRITICAL PERFORMANCE RULE

AEM Performance Principles (REQUIRED)

Based on AEM's performance guidelines:

  • Phase E (Eager): Minimal DOM creation for LCP elements only
  • Phase L (Lazy): Progressive enhancement of below-fold content
  • Phase D (Delayed): Third-party DOM modifications after 3+ second delay

Phase E - LCP Critical DOM Operations (REQUIRED)

Immediate DOM insertion for LCP elements, minimal complexity

// ✅ REQUIRED - Phase E: Simple DOM structure for LCP
const createLCPElement = (content) => {
  const isFirstSection = true; // Determining logic for first section
  
  if (isFirstSection) {
    // Phase E: Keep DOM structure minimal for LCP
    const el = createTag('div', { class: 'hero-content' });
    el.textContent = content; // Simple text content first
    
    // Return immediately for LCP
    return el;
  }
};

// ✅ REQUIRED - Progressive enhancement pattern
const enhanceLCPElement = (element, enhancementData) => {
  // Phase L: Add enhancements after LCP
  setTimeout(() => {
    const enhancedContent = createTag('div', { class: 'enhanced-content' });
    enhancedContent.innerHTML = enhancementData;
    element.appendChild(enhancedContent);
  }, 0);
};

createElement Pattern (REQUIRED)

Always use the standardized createTag pattern from utils.js:

// ✅ CORRECT - Preserves events and performance (all phases)
const el = createTag('div', { class: 'my-class' }, content);
parent.append(el);

// ❌ WRONG - Breaks event listeners and re-parses DOM  
parent.innerHTML = '<div class="my-class">content</div>';

Phase-Aware DOM Construction (REQUIRED)

// ✅ REQUIRED - Build DOM progressively by phase
class ComponentBuilder {
  constructor(element) {
    this.element = element;
    this.isFirstSection = element.closest('.section') === document.querySelector('.section');
  }
  
  init() {
    if (this.isFirstSection) {
      // Phase E: Critical structure only
      this.buildCriticalDOM();
    } else {
      // Phase L: Build with intersection observer
      this.buildWithLazyLoading();
    }
  }
  
  buildCriticalDOM() {
    // Phase E: Minimal DOM for LCP
    const basicStructure = this.createBasicStructure();
    this.element.appendChild(basicStructure);
    
    // Queue enhancements for Phase L
    this.queueEnhancements();
  }
  
  buildWithLazyLoading() {
    // Phase L: Full DOM construction with intersection observer
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          this.buildFullDOM();
          observer.unobserve(entry.target);
        }
      });
    }, { rootMargin: '200px' });
    
    observer.observe(this.element);
  }
  
  createBasicStructure() {
    // Simple DOM for LCP - no nested complexity
    return createTag('div', { class: 'basic-content' }, this.getBasicContent());
  }
  
  buildFullDOM() {
    // Phase L: Rich DOM structure
    const fullStructure = this.createEnhancedStructure();
    this.element.appendChild(fullStructure);
  }
}

Read the full file on GitHub · 449 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 449 lines · 2,921 tokens per session scan A d8aad088f48d

Subscribe to this mod's changes

dom-manipulation-best-practices is a cursor rule published in the GitHub repository adobecom/express-milo (6 stars, last pushed 2d ago), licensed Apache-2.0. It adds 2,921 tokens to every session, about $0.0146 per session on Opus 5. A static security scan graded it A with 0 findings. It is 100% identical to dom-manipulation-best-practices, differing in 0 lines, and is treated as a copy.