As you know, Magento 2 comes with latest technology like HTML5, CSS3, Bootstrap, RequireJs, PHP 7, etc. It also includes some other techniques that decrease the load time of page. As per the Magento 2, When a browser loads a web page and requests a static view file such as a JavaScript, CSS, image file, or another page asset, the Magento application processes the requested file before it returns the file to the browser. In this blog post, we will know how to deploy static view files in Magento 2.

What is a static view file?

Static means it can be cached for a site (that is, the file is not dynamically generated). Examples include images and CSS generated from LESS and View refers to presentation layer from MVC.

Static view files are located in the /pub/static directory, and some are cached in the /var/view_preprocessed directory as well.

For Developer Mode: When you install or enable a new extension, it might load new JavaScript, CSS, layouts. To avoid issues with static files, you must clean the old files to make sure you get all the changes for the new extension.

How to clear static view files?

1) Manually by clearing the pub/static and var/view_preprocessed directories and subdirectories. except for pub/static/.htaccess.
2) In the Magento 2 Admin. Go to System > Tools > Cache Management and click Flush Static Files Cache.

How to deploy static view files?

Below are the steps to deploy static view files.

  • Log in to the Magento server as, or switch to, the Magento file system owner.
  • Delete the contents of /pub/static.
  • Run the static view files deployment command /bin/magento setup:static-content:deploy

Command with options:

Here, [lang] means Space-separated list of ISO-636 language codes for which to output static view files (Default is en_US.). You can find the list by running magento info:language:list.
[–dry-run] Include to view the files output by the tool without outputting anything.

By following the above steps you can deploy static view files in Magento 2. If you have any queries or difficulties with the above steps and commands then feel free to add comments.