What is NitroPack’s Keep HTML Comments for WordPress?

Table of contents

What is NitroPack’s Keep HTML Comments for WordPress?

TL;DR

The “Keep HTML Comments” feature gives you fine control over which HTML comments are preserved during optimization. This ensures compatibility with plugins, third-party tools, or SEO practices that rely on inline comments—without sacrificing speed or stability.

HTML comments aren’t always just notes for developers. On WordPress websites, they often serve important roles:

  1. SEO tools use them to inject schema markup or structured data
  2. Plugins rely on them for placeholders or dynamic content rendering
  3. Debugging tools use them to track page elements or processes

By default, NitroPack removes HTML comments to reduce file size and increase load speed. But in cases where those comments matter, you can keep them—selectively or globally.

This strikes the perfect balance between performance and compatibility.

What does “Keep HTML Comments” mean?

“Keep HTML Comments” allows you to retain specific HTML comments in your site’s source code—either:

  1. All comments
  2. Only those matching a custom pattern (e.g. containing schema.org or yoast)
  3. Or none at all (default, for max performance)

This ensures critical HTML comments used by SEO tools, A/B testing scripts, or plugin shortcodes aren’t accidentally removed.

Benefits:

  • Preserve schema or structured data hints
  • Avoid plugin or template breakage
  • Improve debugging and markup validation
  • Maintain compatibility with third-party scripts or analytics

HTML comments are notes or pieces of information placed within your HTML code that are not visible to users on the page but can be seen in the page source by developers or tools.

HTML comments are commonly:

  • Not rendered in the browser (users won’t see them)
  • Used for documentation, notes, or temporary code blocks
  • Sometimes used by plugins or scripts for functional purposes (like placeholders, schema markup, or A/B testing markers)Uses include developer notes, conditional content or browser-specific hacks, SEO plugins, and templating and CMS tools.

With vs Without “Keep HTML Comments” (Example)

HTML comments can carry meaningful logic for plugins or dev tools. Automatically stripping all of them may break functionality or reduce markup clarity.

This feature allows you to selectively preserve them when necessary.

ScenarioWithout Keep HTML CommentsWith Keep HTML Comments
File sizeSlightly smallerSlightly larger (depends on kept comments)
SEO markup (e.g., Yoast, Schema)May be removedPreserved correctly
Plugin compatibilityRisk of layout/data issuesMaintained
Debug visibility (HTML)Hidden from sourceVisible for inspection
Control over comment removalNot availableFull control via pattern matching

Why You Should Keep Some HTML Comments

Not all comments are disposable. While stripping HTML comments helps reduce size, it can also break subtle or critical functionality.

This feature is especially useful when:

  • Using SEO plugins that rely on comments for structured data (e.g., Yoast, Rank Math)
  • Running A/B testing tools or custom scripts using comment markers
  • Debugging layouts or inspecting WordPress rendering quirks
  • Avoiding errors from page builder templates that include comment-based logic

Indirectly, this feature can also help prevent render delays and user experience regressions often seen in Google PageSpeed Insights reports.

How “Keep HTML Comments” Works in NitroPack

When this feature is enabled, NitroPack:

  • Parses all HTML comments during optimization
  • Matches each against your settings (e.g., keep all or only matching specific text)
  • Preserves only the ones you need
  • Continues applying full optimization, including minification and compression
Use CaseRecommended Action
Using SEO plugin with HTML-based schemaEnable and filter by keyword
Relying on comments for A/B test placementKeep specific comments
Debugging layout with HTML markersTemporarily keep all comments
No plugin depends on commentsKeep disabled (default setting)

NitroPack vs Manual Comment Filtering

Manually controlling which HTML comments are kept means editing your theme files or injecting logic in your cache pipeline. NitroPack handles it automatically and with zero risk of breaking pages.

FeatureManual SetupNitroPack Automation
Comment filteringRequires custom regex✅ Built-in
Per-pattern control❌ Difficult to implement✅ Easy pattern matching
Avoids breaking SEO tools⚠️ Risky✅ Safe
Works with all themes/plugins❌ Needs manual testing✅ Fully compatible
Debug support❌ Manual toggle✅ Easy on/off from dashboard

How to Enable “Keep HTML Comments” in NitroPack

Getting started is simple:

  1. Log in to your NitroPack dashboard
  2. Go to Cache Settings >> HTML & CSS
  3. Enable Keep HTML Comments
  4. Purge your cache to apply changes
Enabling NitroPack's Keep HTML comments feature in the web app

FAQs

Will this slow down my site?

Very slightly—if you preserve many large comments. But in most cases, the impact is negligible, and the benefit of preserved functionality outweighs the size increase.

Will enabling this affect NitroPack’s HTML minification?

No. Minification and compression still apply. This setting only affects HTML comments.

Should I keep comments for SEO plugins?

Yes—if you use plugins that inject schema or structured data via HTML comments (like Yoast or Rank Math), you should preserve those comments.

Lora Raykova
By Lora Raykova

User Experience Content Strategist

Lora has spent the last 8 years developing content strategies that drive better user experiences for SaaS companies in the CEE region. In collaboration with WordPress subject-matter experts and the 2024 Web Almanac, she helps site owners close the gap between web performance optimization and real-life business results.