Angular - Performance OptimizationWhich import style in Angular best supports tree shaking to exclude unused code?Aimport * as Library from 'library';Bimport { specificFunction } from 'library';Cconst Library = require('library');Dimport 'library';Check Answer
Step-by-Step SolutionSolution:Step 1: Analyze import stylesNamed imports (import { specificFunction } from 'library';) allow bundlers to identify and remove unused exports.Step 2: Understand why others failNamespace imports (B) and side-effect imports (D) include entire modules, preventing tree shaking.Final Answer:import { specificFunction } from 'library'; -> Option BQuick Check:Named imports enable tree shaking [OK]Quick Trick: Use named imports for effective tree shaking [OK]Common Mistakes:Using namespace imports which include whole modulesUsing require() which is CommonJS and not tree-shakeableImporting modules only for side effects
Master "Performance Optimization" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Advanced Patterns - Facade service pattern - Quiz 9hard Angular Signals - Effect for side effects - Quiz 1easy Angular Signals - Why signals are introduced - Quiz 3easy Internationalization and Accessibility - Locale switching - Quiz 2easy Performance Optimization - Lazy loading routes and modules - Quiz 15hard Server-Side Rendering - Pre-rendering static pages - Quiz 15hard Standalone Components - Bootstrapping with standalone - Quiz 14medium State Management - Why state management matters - Quiz 6medium State Management - Service-based state management - Quiz 13medium Testing - Testing with fixtures and debug elements - Quiz 6medium