In this quick tutorial, we will learn what is Magento 2 Static Content and how to deploy Magento 2 Static Content.
First, we learn what is Static View.
What is Magento 2 Static View?
Magento Static View is made of two terms.
Static: It means the file is the same for every reload of the webpage. Static files and pages can be cached—for example, images, text etc.
View: The presentation layer.
The static view files deployment command enables you to write static files to the Magento file system when the Magento software is set for production mode.
You will find the Static View files in the <magento_root>/pub/static directory, and some are cached in the <magento_root>/var/view_preprocessed directory as well.
Magento Modes
Magento platform comes with three modes.
- Default: The mode when you install the Magento. Basic configurations.
- Developer: The mode where the developer works. The caching is disabled, and the changes can be viewed quickly in this mode. It is also known as Maintenance mode.
- Production: The mode for the live store. With all the speed and performance optimizations, caching enabled mode to boost the store speed.
Magento modes affect the deployment of Static View files.
- Default and Developer Mode: Magento generates the Static View on-demand. However, the rest are cached in a file for quick access.
- Production Mode: Static files are not generated or cached.
You can find the mode of your Magento store by quickly running the following commands in the root directory:
php bin/magento deploy:mode:show
You have to write static view files manually to the file system of your Magento 2 store by using the CLI command. After running the CLI command, you can restrict permissions to limit vulnerabilities and prevent malicious overwriting of files.
Now you know what is Static View, where the files are located, and Modes that affect them; let’s see how to deploy Static View.
Magento 2 Deploy Static Content Using CLI
Follow the steps to deploy static view files:
- Log in to the Magento server as the file system owner.
- Delete the contents of <magento_root>/pub/static, except for the .htaccess file. Do not delete this file.
- Run the code to deploy static view files:
php bin/magento setup:static-content:deploy
The complete code looks like this:
bin/magento setup:static-content:deploy [<languages>] [-t|--theme[="<theme>"]] [--exclude-theme[="<theme>"]] [-l|--language[="<language>"]] [--exclude-language[="<language>"]] [-a|--area[="<area>"]] [--exclude-area[="<area>"]] [-j|--jobs[="<number>"]] [--no-javascript] [--no-css] [--no-less] [--no-images] [--no-fonts] [--no-html] [--no-misc] [--no-html-minify] [--no-parent] [-f|--force]
The following table explains this command’s parameters and values.
Magento 2 Static Content Deploy in Breeze Platform
If you use Breeze to manage your Magento store, you can deploy static content from the platform itself.
- Follow the steps to clear all website cache.
- Login to your Breeze platform
- Select the Company you like to work on
- Click on the ‘Sites’ to open the site list
- Open the ‘Website’
- Go to the ‘Magento’ Section
- Deploy the Static Content
You can also view the log to see the static content history of the store.
Deploy static view files without installing Magento
If you want to build processes and do not want to risk the sensitive production machine, you must run the deployment in a different, non-production environment.
Follow the steps to do this:
- Export the configuration from the production system:
bin/Magento app:config:dump
- Copy the exported files to the non-production code base.
- Run bin/Magento setup:static-content:deploy.
Final Words
That’s it.
In this tutorial, we learn to deploy static content on Magento 2. If you encounter an issue, please leave it in the comments.