// blog/developer/
Back to Blog
Developer · Published August 21, 2026 · 9 min read · By Toine

Debugging Minified Code: Pretty-Print and Source Maps

Debugging Minified Code: Pretty-Print and Source Maps

Minification is a necessary trade. Build tools strip whitespace, shorten names, remove comments, and compress code into a dense line. The result loads faster and transfers fewer bytes. The problem comes when something breaks in production and you are staring at e.map(t=>t.a+t.b) trying to find the original source.

Pretty-printers add back whitespace and indentation so the code is readable again. Source maps go further, mapping minified code back to the exact original file, line, and column. Together they make production debugging practical instead of painful.

This guide covers the tools and techniques for debugging minified JavaScript, CSS, and HTML, from quick pretty-print fixes to proper source map workflows.

* * *

Pretty-Printing in Browser DevTools

Every modern browser has a built-in pretty-printer. In Chrome DevTools, open the Sources panel, find a minified file, and click the {} button at the bottom of the code viewer. The file reformats instantly with proper indentation and line breaks.

Firefox has the same feature in its Debugger panel. Safari has it in the Sources tab. The formatting is purely visual and does not affect the running code.

What pretty-printing gives you:

  • Readable code structure with proper indentation
  • Individual lines you can set breakpoints on
  • Visible control flow (if/else blocks, loops, function boundaries)

What pretty-printing does not give you:

  • Original variable names (minifiers rename userName to a)
  • Original comments (stripped during minification)
  • Module structure (bundled code is merged into one file)
  • Type information (TypeScript types are removed during compilation)

Pretty-printing is the quick fix when you need to debug something right now and source maps are not available. For regular production debugging, source maps are the proper solution.

Use the JavaScript Minifier to minify your development code when testing the minification process. This helps you verify that your code behaves the same before and after minification.

* * *

Source Maps: The Complete Solution

Source maps are files that map minified code back to the original source. They contain the mapping between every character in the minified output and its position in the original files. When the browser loads a source map, DevTools shows the original code instead of the minified version.

A source map file looks like this (simplified):

`json { "version": 3, "sources": ["src/components/Button.tsx", "src/utils/helpers.ts"], "names": ["handleClick", "formatDate", "isValid"], "mappings": "AAAA,SAAS..." } `

The mappings field contains a Base64 VLQ encoded string that maps positions between files. You never need to read this manually. The browser and DevTools handle the decoding.

Generate source maps during your build:

  • Webpack: devtool: 'source-map' in your config
  • Vite/Rollup: build: { sourcemap: true } in vite.config.ts
  • esbuild: --sourcemap flag
  • TypeScript: "sourceMap": true in tsconfig.json

The source map is linked to the minified file via a comment at the end:

` //# sourceMappingURL=bundle.js.map `

DevTools reads this comment and fetches the source map file automatically.

Browser DevTools showing formatted versus minified JavaScript side by side
Browser DevTools showing formatted versus minified JavaScript side by side
* * *

Source Map Security for Production

Publishing source maps means anyone can view your original source code. For open-source projects, that is fine. For commercial software, you need a strategy.

Option 1: Do not publish source maps. Build them, store them privately, and upload them to your error monitoring service (Sentry, Datadog, etc.). These services use the source maps server-side to decode error stack traces without exposing the maps to the public.

Option 2: Restrict access. Serve source maps only to authenticated users or from internal URLs. Configure your server to require a token or internal network access for .map files.

Option 3: Hidden source maps. Generate source maps but do not include the sourceMappingURL comment in the minified files. You can manually load them in DevTools when needed.

Option 4: Publish them. Many teams decide that the security risk of visible source code is low compared to the debugging benefit. If your code is the product (like a SaaS application), the server-side logic is not exposed. Only client-side code is visible, which can already be reverse-engineered from the minified version.

The most common approach for production applications is Option 1: generate source maps, upload them to your error monitoring service, and do not serve them publicly. This gives you full debugging capability without exposing source code.

* * *

Debugging Minified CSS

CSS debugging follows similar patterns but with some CSS-specific twists.

Browser DevTools automatically pretty-print CSS in the Styles panel. You can see the original file and line number if source maps are available. The Elements panel shows computed styles regardless of minification.

Common CSS debugging scenarios with minified code:

Finding which rule applies: the Computed tab in DevTools shows the final computed value and which rule set it. Click through to the source. Even with minified CSS, the Computed tab resolves everything.

Overriding a stubborn style: if you cannot figure out why a rule is not applying, add a temporary inline style to confirm the visual change works. Then use DevTools to trace the specificity conflict.

Debugging CSS custom properties: minifiers may rename CSS custom properties or inline their values. Check whether your custom property references survived minification by inspecting computed styles.

The CSS Minifier preserves CSS functionality during compression. Use it to verify that your styles produce identical results before and after minification. If a minifier changes the output, the issue is usually a CSS specificity or source order problem that the minification process exposed.

For HTML debugging, the HTML Minifier removes whitespace and optional tags but preserves the DOM structure. Any HTML rendering difference after minification indicates an issue with optional tags or whitespace-dependent layouts.

Terminal window with source map configuration for production debugging
Terminal window with source map configuration for production debugging
* * *

Production Debugging Workflow

A reliable production debugging workflow combines several techniques:

Step 1: Reproduce with error monitoring. Sentry, Datadog, or similar tools capture the error, stack trace, and user context. With uploaded source maps, the stack trace shows original file names and line numbers.

Step 2: Reproduce locally. Create the same conditions locally using the production build. Run npm run build then npm run start (or equivalent) to test against the same minified code.

Step 3: Source map debugging. If you stored source maps, load them in DevTools manually. In Chrome, go to Sources, right-click in the file list, select "Add source map," and point to the local map file.

Step 4: Conditional breakpoints. In the pretty-printed minified code, set a conditional breakpoint. Right-click on a line number, select "Add conditional breakpoint," and add a condition like userId === '12345'. This lets you catch the exact scenario that triggered the bug.

Step 5: Console evaluation. Even with minified variables, you can evaluate expressions in the console while paused at a breakpoint. The scope panel shows all local variables (even with short names). Hover over variables in the source to see their values.

Step 6: Network and timing. Many production bugs are timing-related. The Network panel shows request/response timing. The Performance panel reveals rendering bottlenecks. These panels work identically with minified and unminified code.

Document the root cause and fix in your issue tracker. Production bugs often reveal edge cases that unit tests did not cover. Write a regression test before deploying the fix.

* * *

FAQ

Do source maps affect page load performance?

No. Source maps are only loaded when DevTools is open. The browser does not download .map files during normal page loads. The only performance cost is the size of the sourceMappingURL comment in the minified file, which is typically under 100 bytes.

Can I generate source maps for already-minified code?

Not accurately. Source maps must be generated during the minification process to create correct mappings. If you have minified code without source maps, pretty-printing is your best option. Some tools attempt to partially reconstruct source maps using heuristics, but the results are unreliable.

Why do my breakpoints move after pretty-printing?

Pretty-printing reformats the code, so line numbers change. Breakpoints set on the minified version may shift when you toggle pretty-printing. Set breakpoints after formatting for consistent behavior. With source maps, breakpoints are set on the original source and always stay in the right place.

Should I include source maps in my development builds?

Yes, always. Development builds should have inline or eval source maps for the fastest debugging experience. The overhead is negligible in development. Only production builds need to consider whether to publish, hide, or privately store source maps.

Key takeaway

### Do source maps affect page load performance.