Table of Contents
What is Static Content Deploy in Magento 2?
Static Content Deployment is a process in Magento 2 that generates static files like CSS, JavaScript, and images used by the frontend. These files are stored in the /pub/static/ directory for faster loading.
One needs to deploy static content to make sure the front end works properly after changes, such as updates to themes, languages, or additional configurations. It improves website performance by serving pre-built files to users instead of generating them on the go.
Below, you can read how to optimize the static content deployment process for specific themes, languages, and areas.
Ways to Speed Up the Static Content Deploy
By default, running the CLI command bin/magento setup:static-content:deploy deploys static files for all themes, which can be very time-consuming. To optimize the process, one can use several options:
1. Deploy for a Specific Theme only
Add a theme name at the end of the command using the –theme option:
bin/magento setup:static-content:deploy --theme="YourThemeVendor/YourThemeName"2. Exclude a Specific Theme from Deployment
Specify a theme to be excluded at the end of the command using –exclude-theme
bin/magento setup:static-content:deploy --exclude-theme="YourThemeVendor/YourThemeName"3. Deploy for a Specific Language
Specify the locale / language at the end of the command:
bin/magento setup:static-content:deploy en_EN4. Exclude Parent Themes
Using –no-parent at the end of the command line ensures that files are not generated for the parent theme:
bin/magento setup:static-content:deploy --theme YourThemeVendor/YourThemeName --no-parent5. Deploy in Developer or Default Mode
To deploy for a specific theme and language in developer mode, run the following command:
bin/magento setup:static-content:deploy -d --theme="YourThemeVendor/YourThemeName" en_EN6. Deploy after Manipulation with Extensions
If you are deploying static content after installing, updating, or deleting Magento extensions, you can simplify it by adding -f at the end:
php bin/magento setup:static-content:deploy -f7. Apply a Patch
At times, static content deployment might get very slow or fail after, for instance, upgrading Magento to a newer version. For such cases, the following patch is recommended to be applied to a project:
You may read more about it here: ACSD-46815: static content deploy fails when using compact strategy
Conclusion
Above, we mentioned the most common ways how to speed up the static content deploy in Magento 2, but it is still not the full list of possible options though. Also, to optimize the static content deployment, one can add several parameters at the same time to target specific themes, areas, or locales.