Magento 2 Static Content Deploy – A Complete Guide

Magento 2 Static Content Deploy - A Complete Guide

The tutorial includes the stepwise method to deploy static content in Magento 2.

Trace the static view files in the static directory of your Magento 2 store at your Magento install dir>/pub/static. Some files are also cached in the Magento install dir>/var/view_preprocessed directory.

One needs to write static view files manually to the file system of the Magento 2 store with CLI command. After running the CLI command, restrict permissions to limit vulnerabilities as well as for the prevention of malicious overwriting of files.

Note: It is required to clean the old files of CSS, Javascript, layouts, etc to make sure that static files run smoothly on enabling a new module in the developer mode.

Clean the generated static view files with the below steps:

Manual method:

Clear all the files under pub/static directory except .htaccess file with the below command:
find . -depth -name .htaccess -prune -o -delete

Automated method:

  • Login to Admin panel
  • Go to Systems > Tools > Cache Management
  • Click the Flush Static Files Cache.

Method for Magento 2 Static Content Deploy via Command Line:

Navigate to Magento admin root folder. Show usages:

Usage:

Arguments:

LanguagesSpace-separated list of ISO-636 language codes for which to output static view files.

 

Options

Description

-f forceDeploy files in any mode
-s –strategy[=STRATEGY]Deploy files using specified strategy.
-a –areaGenerate files only for the specified areas. [default: [“all”]] (multiple values allowed)
–exclude-area[=EXCLUDE-AREA]Do not generate files for the specified areas. [default: [“none”]] (multiple values allowed)
-t–theme[=THEME]Generate static view files for only the specified themes. [default: [“all”]] (multiple values allowed)
–exclude-theme[=EXCLUDE-THEME]Do not generate files for the specified themes. [default: [“none”]] (multiple values allowed)
-l–language[=LANGUAGE]Generate files only for the specified languages. [default: [“all”]] (multiple values allowed)
–exclude-language[=EXCLUDE-LANGUAGE]Do not generate files for the specified languages. [default: [“none”]] (multiple values allowed)
-j

 

 

–jobs[=JOBS]Enable parallel processing using the specified number of jobs. [default: 0]
–symlink-localeCreate symlinks for the files of those locales, which are passed for deployment, but have no customizations.
–content-version=CONTENT-VERSIONCustom version of static content can be used if running deployment on multiple nodes to ensure that static content version is identical and caching works properly.
–refresh-content-version-onlyRefreshing the version of static content only can be used to refresh static content in browser cache and CDN cache.
–no-javascriptDo not deploy JavaScript files.
–no-cssDo not deploy CSS files.
–no-lessDo not deploy LESS files.
–no-imagesDo not deploy images.
–no-fontsDo not deploy font files.
–no-htmlDo not deploy HTML files.
–no-miscDo not deploy files of other types (.md, .jbf, .csv, etc.).
–no-html-minifyDo not minify HTML files.
-h–helpDisplay this help message
-q–quietDo not output any messages
-V–versionDisplay this application version
–ansiForce ANSI output
–no-ansiDisable ANSI output
-n–no-interactionDo not ask any interactive question
-v|vv|vvv–verboseIncrease the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Simply run the below command to deploy static content in your store when you install an extension

That was all about the Magento 2 Static Content Deploy!

Follow the guide that’ll help to boost the speed of your Magento 2 store!

Please feel free to mention any doubts in the tutorial in the Comments section below. I’d be happy to help 🙂

Also, a reminder to rate the post with 5 stars!

Thank you

5
(based on 9 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply