3

As mentioned in this link: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-static-view.html

Static view files deployment is affected by Magento modes as follows:

Developer mode: Magento generates them on demand, but the rest are cached in a file for speed of access.

Default and production modes: Static files are not generated or cached.

You must write static view files to the Magento file system manually using the command discussed in this topic; after that, you can restrict permissions to limit your vulnerabilities and to prevent accidental or malicious overwriting of files.

Just wanted to know, why static files are not generated or cached in production mode or default mode as this mode suppose to work faster and do more caching ? Not generating static files in these modes seems reasonable but I have confusion about why no cache is going to generated in these modes?

2 Answers 2

2

Here is a clarification between the three different modes (source: Magento U Fundamentals course). In bold, the specific points related to your question.

Developer mode

  • Static file materialization is not enabled.
  • Uncaught exceptions displayed in the browser
  • Exceptions thrown in error handler, not logged
  • System logging in var/report, highly detailed.

You should use the Developer mode while you are developing customizations or extensions. The main benefit to this mode is that error messages are visible to you. It should not be used in production because of its impact on performance. In Developer mode, static view files are generated every time they are requested. They are written to the pub/static directory, but this cache is not used. This has big performance impact, but any changes a developer makes to view files are immediately visible.

Uncaught exceptions are displayed in the browser, rather than being logged. An exception is thrown whenever an event subscriber cannot be invoked.

System logging in var/report is highly detailed in this mode.

Production mode

  • Deployment phase on the production system; highest performance
  • Exceptions are not displayed to the user -- written to logs only.
  • This mode disables static file materialization.
  • The Magento docroot can have read-only permissions.

You should run Magento in Production mode once it is deployed to a production server.

Production mode provides the highest performance in Magento 2.

The most important aspect of this mode is that errors are logged to the file system and are never displayed to the user. In this mode, static view files are not created on the fly when they are requested; instead, they have to be deployed to the pub/static directory using the command-line tool. The generated pages will contain direct links to the deployed page resources.

Any changes to view files require running the deploy tool again.

Because the view files are deployed using the CLI tool, the web user does to need to have write access. The Magento pub/static directory can have read-only permissions, which is a more secure setup on a publicly accessible server.

Default mode

  • Used when no other mode is specified
  • Hides exceptions from the user and writes them to log files
  • Static file materialization is enabled.
  • Not recommended / not optimized for production: caching impacts performance negatively.

As its name implies, Default mode is how the Magento software operates if not other mode is specified.

In this mode, errros are logged to files in var/reports and are never shown to a user. Static view files are materialized on the fly and then cached.

In contrast to the developer mode, view file changes are not visible until the generated static view files are cleared.

Default mode is not optimized for a production environment, primarily because of the adverse performance impact of static files being materialized on the fly rather than generating and deploying them beforehand.

In other words, creating static files on the fly and caching them has a greater performance impact than generating them using the static file creation command line tool.

3
  • I read these but didn't get the point. Why static files caching is "disabled" in production mode ? Apr 20, 2016 at 9:37
  • @MichelGokan because materializing them on the fly is not performance friendly. Thus, you need to deploy the static files when using production mode. I think you're misunderstanding caching and materializing. Apr 20, 2016 at 9:39
  • Thanks for your kind helps. Can you help me with this concept? I asked a separate question here: magento.stackexchange.com/questions/111701/… Apr 20, 2016 at 10:24
0

I stumbled on a related problem where the assets for the admin panel did not generate on production mode.

According to the docs, both frontend and backend assets should be generated when running setup:static-content:deploy, but in my case, only the frontend was built.

This can be fixed by simply running the deploy command for the backend separately:

bin/magento setup:static-content:deploy --area adminhtml -f en_GB en_US

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.