We use different builds to make our styles faster for users in production and easier to work with during development.
Production vs development builds in SASS
Start learning this pattern below
Jump into concepts and practice - no test required
sass --style=expanded input.scss output.css # for development sass --style=compressed input.scss output.css # for production
expanded style makes CSS easy to read with spaces and new lines.
compressed style removes spaces and new lines to make CSS smaller.
sass --style=expanded styles.scss styles.css
sass --style=compressed styles.scss styles.min.css
This HTML file links to a CSS file created from Sass. Use --style=expanded for development to see readable CSS. Use --style=compressed for production to have smaller CSS files that load faster.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Production vs Development CSS</title> <link rel="stylesheet" href="styles.css"> </head> <body> <header> <h1>Welcome!</h1> </header> <main> <p>This page shows how CSS looks in development and production builds.</p> </main> </body> </html>
Development builds help you find and fix style problems quickly.
Production builds make your website faster by reducing file size.
Always test your production build to make sure styles still work well.
Use expanded style for easy-to-read CSS during development.
Use compressed style for small, fast CSS in production.
Switching builds helps balance between easy coding and fast websites.
Practice
expanded style in Sass during development?Solution
Step 1: Understand the purpose of
Theexpandedstyleexpandedstyle formats CSS with indentation and line breaks, making it easy to read.Step 2: Compare with production needs
In development, readability helps debugging, unlike production where file size matters more.Final Answer:
To make the CSS easier to read and debug -> Option DQuick Check:
Expanded style = readable CSS [OK]
- Confusing expanded with compressed style
- Thinking expanded reduces file size
- Assuming expanded removes comments
style.scss into compressed CSS for production?Solution
Step 1: Identify the flag for compressed output
The--style=compressedoption tells Sass to minify CSS for production.Step 2: Check other options
expandedis for readable CSS,--watchwatches files but doesn't set style,nestedis another readable format.Final Answer:
sass style.scss style.css --style=compressed -> Option BQuick Check:
Compressed style = minified CSS [OK]
- Using expanded style for production
- Confusing --watch with style option
- Using nested style for production
sass input.scss output.css --style=compressed
What will the CSS output look like?
Solution
Step 1: Understand the compressed style effect
Thecompressedstyle removes spaces and line breaks to minimize file size.Step 2: Compare with other styles
Readable indentation and comments are removed in compressed output to optimize loading speed.Final Answer:
CSS with all unnecessary spaces and line breaks removed -> Option AQuick Check:
Compressed style = minified CSS [OK]
- Expecting readable CSS with compressed style
- Thinking comments stay in compressed output
- Confusing nested style with compressed
sass style.scss style.css --style=compressed but the output CSS is still very large and readable. What is the likely cause?Solution
Step 1: Check if output file is updated
If the output CSS looks unchanged, it might be cached by the system or browser.Step 2: Verify compilation flags and file saving
Since the command uses--style=compressedand file is saved, caching is the likely issue.Final Answer:
The output file is cached and not updated -> Option AQuick Check:
Cache can cause stale CSS output [OK]
- Assuming wrong flag without checking command
- Not saving source file before compiling
- Blaming Sass version without checking cache
Solution
Step 1: Change CSS style for production
Switching fromexpandedtocompressedreduces file size for faster loading.Step 2: Manage source maps for production
Disabling source maps in production avoids extra files and speeds up loading.Final Answer:
Change --style from expanded to compressed and disable source maps -> Option CQuick Check:
Compressed + no source maps = optimized production CSS [OK]
- Leaving source maps enabled in production
- Keeping expanded style for production
- Confusing enabling source maps with optimization
