Remove HTML Comments in Production: Vite, Vue and Next.js (2026)

Our scanner flags Suspicious HTML Comments when the HTML your homepage serves contains a comment mentioning things like todo, password, key, admin, staging or debug. Anyone can read those with View Source. It's a low-severity finding, and most of the time it's a stale TODO. Some of the time it's a staging URL or a test key, and you won't know which until you look.

The part that surprises people is where the comment comes from. Your build tool already strips most comments. The ones that survive come from a handful of predictable places.

TL;DR

Vite strips comments from your JavaScript but ships index.html comments untouched (we tested Vite 8.3.5). Vue strips template comments in production builds. React's JSX comments never reach the HTML at all. Fix the survivors with a small build plugin, never by regex-stripping server-rendered Vue HTML, and rotate any key that was ever in a comment.

What we tested

We built a tiny Vite 8.3.5 app with comments in three places: index.html, a JavaScript file, and a Vue 3.5.44 template. Then we ran a production build and read what came out.

Where the comment livesShips to production?
index.html (Vite)Yes, word for word
JavaScript source (// TODO, /* */)No, the minifier drops it
JavaScript source, with build.sourcemap: trueYes, inside the .js.map file
Vue template, NODE_ENV=productionNo
Vue template, development buildYes
JSX {/* comment */}No, it's a JavaScript comment and never becomes HTML

Here's the index.html we started with:

index.html (source)
<head>
  <title>t</title>
  <!-- TODO: remove staging api key before launch: sk_test_123 -->
</head>
<body>
  <div id="app"></div>
  <!-- admin panel lives at /internal-admin -->
  <script type="module" src="/src/main.js"></script>
</body>

And dist/index.html after vite build: both comments, exactly as written. That's the file every visitor downloads first.

The source map result is the sneaky one. A // TODO: hardcoded admin password is hunter2 line vanished from the minified bundle, so a quick look at the deployed .js says you're clean. The .js.map next to it contained the line verbatim, because a source map's job is to carry your original source.

Step 1: Find what's actually live

Don't search your repo first. Search what you serve, because that's what the scanner (and anyone else) reads.

1

Open your live homepage, press Ctrl+U (Cmd+Option+U on a Mac) and search the page for <!--. Or from a terminal:

curl -s https://yourapp.com | grep -o '<!--.*-->'

Ignore <!--[-->, <!--]--> and <!---->. Those are Vue and Nuxt hydration markers, not your comments. Note anything that reads like a person wrote it.

2

For each real comment, find its source. grep -rn "the comment text" . in your project usually lands on index.html, a layout component, a CMS field, or a third-party embed snippet someone pasted in.

Step 2: Strip comments at build time

Vite (React, Svelte, plain JS, Vue SPA)

Add a plugin that removes comments from index.html during vite build only. It skips <!--[if conditional comments in case an old email or IE snippet depends on them.

vite.config.js
export default {
  plugins: [
    {
      name: 'strip-html-comments',
      apply: 'build',
      transformIndexHtml: (html) =>
        html.replace(/<!--(?!\[if)[\s\S]*?-->/g, ''),
    },
  ],
}

We ran the same test build with this plugin in place and dist/index.html came out with no comments and the script tag intact. Merge the plugin into your existing plugins array rather than replacing it.

Vue and Nuxt

Nothing to add in the normal case: Vue's compiler drops template comments when NODE_ENV is production, and vite build and nuxt build set that for you. If your own comments show up on the live site anyway, check two things:

  • Your host isn't building with NODE_ENV=development (look in the build environment variables).
  • Nobody set comments: true in vue.compilerOptions or the Vite Vue plugin options.

You can force it either way with compilerOptions: { comments: false }.

Don't run a comment-stripping regex over Nuxt or Vue server-rendered HTML (a Nitro hook, middleware, or a CDN rewrite). In our test, Vue's renderer produced <ul><!--[--><li>a</li><li>b</li><!--]--></ul><!----> for a two-item list and a false v-if. Those markers are how the client hydrates the page. Strip them and you get hydration mismatches.

Next.js and React

JSX comments ({/* ... */}) are JavaScript and never render. If the scanner finds comments on a Next.js site, they're arriving through a string: dangerouslySetInnerHTML, a <Script> or third-party snippet, or HTML pulled from a CMS. Clean the source of that string. There's no build flag to flip.

Source maps

If vite.config.js has build.sourcemap: true, or your framework publishes .map files, your JavaScript comments are public even though the bundle looks clean. Set it to false or 'hidden' for production. Our guide to fixing exposed source maps covers each framework.

Step 3: Treat secrets in comments as leaked

Removing the comment fixes the finding. It doesn't un-publish what was already served. Search engines, archive crawlers and anyone who looked while it was live may have a copy.

  • A key or token in a comment: rotate it now, then remove the comment. Even a sk_test_ key gives someone access to your test-mode data.
  • An internal path or staging URL: make sure that path requires auth. A comment that says /internal-admin is only a problem if /internal-admin opens without a login.
  • A TODO about unfinished security ("add rate limiting", "check permissions here"): that's a bug report to yourself. Fix the bug, not just the comment.

Why the finding can fire on harmless comments

Our check reads the HTML your server returns for the homepage, skips comments under five characters and [if conditionals, and flags any comment containing one of twelve keywords. It matches substrings, so <!-- keyboard shortcuts --> trips it on key, and <!-- hackathon winners section --> trips it on hack. Common analytics snippets like <!-- Google Tag Manager --> don't.

That's deliberate. A false positive costs you a minute of reading. A missed <!-- staging key: ... --> costs a lot more. If what we flagged is genuinely harmless, the build-time strip above clears it anyway, so the finding stays gone.

Are HTML comments a security risk?

Usually a small one. A comment is visible to anyone who opens View Source, so the risk is whatever the comment says. A TODO about a button is harmless. A note naming an admin path, a staging URL or a test key hands an attacker a map. Our scanner rates it low severity for that reason, but a key in a comment is a leaked key and needs rotating.

Does Vite remove HTML comments from index.html?

No. We built a Vite 8.3.5 project with two comments in index.html and both shipped to dist/index.html unchanged. Vite strips comments from your JavaScript, but it copies index.html comments through. A five-line transformIndexHtml plugin removes them at build time.

Does Vue remove template comments in production?

Yes, when the template compiler runs with NODE_ENV=production, which a normal vite build or nuxt build does. In our test with Vue 3.5.44 the same comment survived a development compile and disappeared from a production one. If you can see your own template comments on the live site, the build ran in development mode or someone set comments: true.

Why does my Nuxt page source have empty comment markers?

Markers like <!--[--> and <!----> are Vue's server-rendering markers for fragments, lists and v-if branches. Hydration uses them to line up the server HTML with the client app, so don't strip them. They carry no information and our scanner ignores them.

Are JavaScript comments removed in production?

From the bundle, yes: the minifier drops them. But if you publish source maps, the .map file contains your original source, comments included. In our Vite test a TODO with a password was gone from the .js file and present word for word in the .js.map.

See What Your Page Source Gives Away

Scan your homepage for developer comments, exposed source maps and the rest of what View Source reveals.

How-To Guides

Remove HTML Comments in Production: Vite, Vue and Next.js (2026)