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:
- SEO tools use them to inject schema markup or structured data
- Plugins rely on them for placeholders or dynamic content rendering
- 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:
- All comments
- Only those matching a custom pattern (e.g. containing schema.org or yoast)
- 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.
Test NitroPack yourself
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.
| Scenario | Without Keep HTML Comments | With Keep HTML Comments |
| File size | Slightly smaller | Slightly larger (depends on kept comments) |
| SEO markup (e.g., Yoast, Schema) | May be removed | Preserved correctly |
| Plugin compatibility | Risk of layout/data issues | Maintained |
| Debug visibility (HTML) | Hidden from source | Visible for inspection |
| Control over comment removal | Not available | Full 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 Case | Recommended Action |
| Using SEO plugin with HTML-based schema | Enable and filter by keyword |
| Relying on comments for A/B test placement | Keep specific comments |
| Debugging layout with HTML markers | Temporarily keep all comments |
| No plugin depends on comments | Keep 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.
| Feature | Manual Setup | NitroPack Automation |
| Comment filtering | Requires 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:
- Log in to your NitroPack dashboard
- Go to Cache Settings >> HTML & CSS
- Enable Keep HTML Comments
- Purge your cache to apply changes
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.