Debugging Minified Code with Step Debugging
You'll learn how to use source maps to step through original, readable code while debugging minified production builds.
The Problem: Minified Code Is Unreadable
When you debug a production site, you often encounter minified JavaScript—files compressed into single lines with cryptic variable names like a, b, and fn. Setting breakpoints and stepping through this code is like trying to read a book where every word has been shortened to a single letter. Technically possible, but painful.
The Solution: Source Maps
Source maps are special files (.map) that act as translation dictionaries between minified code and your original source code. When DevTools detects a source map, it automatically reconstructs your readable code, complete with:
- Original variable names
- Proper formatting and indentation
- Comments
- Original file structure
How It Works
When you set a breakpoint in the Sources panel and step through code (using Step Over, Step Into, or Step Out), DevTools uses the source map to show you the original code, even though the browser is actually running the minified version.
The watch expressions, call stack, and scope panel all display values using your original variable names, not the minified ones. It's like having a simultaneous translator for your code.
Practical Application
- Chrome DevTools automatically loads source maps if they're referenced in your minified files
- Set breakpoints in the readable, mapped source files
- Step through code normally—DevTools handles the mapping behind the scenes
- Inspect variables and scope using your original identifiers
Without source maps, you'd be forced to step through function a(b,c){return b+c}. With them, you see function calculateTotal(price, tax) { return price + tax; }.
Key Takeaway: Source maps bridge the gap between production minified code and development readability, making step debugging in production builds nearly identical to debugging your original source code.