Avoid SCD on Both Phases
Understanding when and how to skip SCD, SKIP_SCD vs SCD_ON_DEMAND, and safe implementation strategies.
Avoiding SCD on Both Phases
Cases for Avoiding SCD
Why Skip Static Content Deployment?
Primary Benefits
- Speed up build process - No time spent generating static content
- Speed up deploy process - Faster deployment execution
- Faster code to Cloud - Get code deployed quicker during development
- Development efficiency - Ideal during development phase of a project
What Happens When You Skip SCD?
Static files from the previous build will still be present in pub/static directory. The existing content is preserved and reused.
Important Context
Skipping SCD is primarily useful during development when you need rapid deployments and haven't changed themes or static content. For production, you typically want SCD to run (preferably in build phase).
How to Skip SCD
Using SKIP_SCD Environment Variable
Specify the SKIP_SCD environment variable in .magento.env.yaml:
Option 1: Skip on Both Build and Deploy
stage:
build:
SKIP_SCD: true
deploy:
SKIP_SCD: true
Option 2: Skip Only on Build
stage:
build:
SKIP_SCD: true
deploy:
SKIP_SCD: false # SCD runs in deploy phase
Option 3: Skip Only on Deploy
stage:
build:
SKIP_SCD: false # SCD runs in build phase
deploy:
SKIP_SCD: true
Expected Results and Behavior
What Happens with SKIP_SCD
| Configuration | Build Phase | Deploy Phase | Result |
|---|---|---|---|
| SKIP_SCD: true (both) | No SCD | No SCD | Uses previous static content |
| SKIP_SCD: true (build only) | No SCD | SCD runs | SCD in deploy (default behavior) |
| SKIP_SCD: true (deploy only) | SCD runs | No SCD | SCD in build (optimal!) |
Static Content Preservation
The contents of pub/static directory will be preserved from the last run. This allows you to reuse previously generated static content.
Common Issues and Pitfalls
Problem 1: Broken Symlinks
Issue
If you previously were deploying static content in the build phase, your pub/static directory will contain three broken symlinks when you skip SCD.
Why This Happens
When SCD runs in build phase, symlinks are created to init/pub/static. When you skip SCD, these symlinks remain but point to non-existent content.
Problem 2: Manual Deployment Doesn't Work
Critical Limitation
Manually running bin/magento setup:static-content:deploy does NOT work in production!
Why?
- Filesystem is read-only in production
pub/staticis a mount point but restricted- You cannot manually generate static content on production servers
Best Approach: Safe Implementation
Recommended Strategy
Method 1: Use SCD_ON_DEMAND
The safest approach for skipping traditional SCD:
stage:
deploy:
SCD_ON_DEMAND: true
Benefits
- No SCD during build or deploy
- Static content generated on first request
- No broken symlinks
- Ideal for development environments
Method 2: Progressive SKIP_SCD Implementation
Step 1: Skip SCD on Build Phase First
stage:
build:
SKIP_SCD: true
deploy:
SKIP_SCD: false # Allow SCD in deploy
Deploy this configuration. This generates static content in deploy phase and populates pub/static properly (no symlinks).
Step 2: After Content is in Environment
Once static content is in the environment and no symlinks are present, you can then enable SKIP_SCD on deploy phase:
stage:
build:
SKIP_SCD: true
deploy:
SKIP_SCD: true # Now safe to skip
Result: Both phases skip SCD, using the existing static content from previous deployment.
Use Case Scenarios
When to Skip SCD
Good Use Cases
- Development: Rapid code iterations without theme changes
- Backend changes: PHP/logic changes that don't affect frontend
- Integration environment: Frequent deployments for testing
- Minor fixes: Bug fixes that don't touch static assets
- Speed testing: Testing deployment performance
Avoid Skipping When
- Production deploys: Always regenerate for production
- Theme changes: Modified templates, CSS, JS
- New locale: Added languages or stores
- First deployment: No existing static content
- Static asset updates: Changed images, fonts, etc.
Complete Workflow Example
Transitioning from Build-Phase SCD to Skip SCD
Current State: SCD in Build Phase
# Current .magento.env.yaml
stage:
build:
SKIP_SCD: false # SCD runs in build
deploy:
SKIP_SCD: true # Skip in deploy
Problem: pub/static contains symlinks to init/pub/static
Step 1: Move SCD to Deploy (Temporarily)
# Updated .magento.env.yaml
stage:
build:
SKIP_SCD: true # Skip in build
deploy:
SKIP_SCD: false # SCD runs in deploy
Deploy this. SCD generates files directly in pub/static, no symlinks.
Step 2: Skip SCD on Both Phases
# Final .magento.env.yaml
stage:
build:
SKIP_SCD: true # Skip in build
deploy:
SKIP_SCD: true # Skip in deploy
Deploy this. Both phases skip SCD, using existing content from Step 1.
Comparison: SKIP_SCD vs SCD_ON_DEMAND
| Aspect | SKIP_SCD | SCD_ON_DEMAND |
|---|---|---|
| When Generated | Uses previous deployment's static content | Generated on first request |
| Build Time | Fast (skipped) | Fast (skipped) |
| Deploy Time | Fast (skipped) | Fast (skipped) |
| First Page Load | Fast (content exists) | Slow (must generate) |
| Requires Previous Deploy | Yes | No |
| Symlink Issues | Possible if transitioning from build SCD | No symlinks |
| Best For | Backend-only changes in development | Development with potential frontend changes |
Exam Tips
Key Points to Remember
- Use cases: Speed up build/deploy, development phase, faster code to Cloud
- SKIP_SCD location: .magento.env.yaml (build and deploy nodes)
- Preservation: pub/static content preserved from last run
- Broken symlinks: Issue when transitioning from build-phase SCD
- Manual deploy limitation: bin/magento setup:static-content:deploy does NOT work in production
- Best approach 1: Use SCD_ON_DEMAND
- Best approach 2: SKIP_SCD on build only first, then skip on deploy
- Two-step process: 1) Skip build only, deploy once, 2) Skip both
- Good for: Development, backend changes, minor fixes
- Avoid for: Production, theme changes, new locales, first deployment
- SKIP_SCD vs SCD_ON_DEMAND: SKIP uses previous content, ON_DEMAND generates on first request