0
0
Angularframework~20 mins

Tree shaking and dead code removal in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Tree Shaking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular's tree shaking affect unused components?

Consider an Angular app where a component is declared but never used in any template or routing. What happens to this component during the build process with tree shaking enabled?

AThe component is removed from the final bundle because it is not referenced anywhere.
BThe component remains in the bundle but is marked as deprecated.
CThe component causes a build error because it is declared but unused.
DThe component is included in the bundle but its template is removed.
Attempts:
2 left
💡 Hint

Think about what tree shaking means for unused code.

📝 Syntax
intermediate
2:00remaining
Which import style helps Angular's tree shaking?

Given a utility library with many functions, which import style allows Angular's build tools to remove unused functions effectively?

Aconst utils = require('library');
Bimport * as utils from 'library';
Cimport 'library';
Dimport { usefulFunction } from 'library';
Attempts:
2 left
💡 Hint

Consider how named imports vs namespace imports affect static analysis.

🔧 Debug
advanced
2:00remaining
Why is dead code not removed in this Angular service?

Look at this Angular service code snippet:

export class DataService {
  fetchData() { return 'data'; }
  unusedMethod() { return 'unused'; }
}

Despite unusedMethod never being called, it remains in the final bundle. Why?

ABecause the service is provided in root and the whole class is included.
BBecause Angular cannot tree shake methods inside classes.
CBecause the build configuration disables tree shaking.
DBecause the method is public and thus always included.
Attempts:
2 left
💡 Hint

Think about how Angular includes services provided in root.

🧠 Conceptual
advanced
2:00remaining
What role does Angular's Ivy compiler play in dead code removal?

How does Angular's Ivy compiler improve tree shaking and dead code removal compared to the previous View Engine?

AIvy disables tree shaking to improve runtime performance.
BIvy bundles all components into a single file, preventing dead code removal.
CIvy generates code that is more modular and easier for build tools to analyze and remove unused parts.
DIvy requires manual configuration to enable dead code removal.
Attempts:
2 left
💡 Hint

Think about how code generation affects static analysis.

state_output
expert
2:00remaining
What is the final bundle size effect of importing a large unused Angular module?

In an Angular app, you import a large feature module but never use any of its components or services. What happens to the final bundle size after build with tree shaking?

AThe module is completely removed from the bundle, no size increase.
BThe entire module and its code remain in the bundle, increasing size significantly.
CThe module code is included but minified to zero size.
DOnly the module's metadata is included, but code is removed.
Attempts:
2 left
💡 Hint

Consider how Angular treats imported modules even if unused.