5

As we all know Magento2 creates static files path itself. You just need to add files in your module namespace/modulename/view/frontend(area)/web or more or like same path for js and css files. Now after running the CLI command setup:static-content:deploy magento will deploy static files under pub/static.

Now if i would like to do some changes in those files then where i should do those changes? In the main file and again need to run the static-content:deploy command ? Or we can do in both places together.

The main question is why magento2 has this feature? For an extra abstraction layer!!..Does that makes any sense?

  • If set in developer mode, Magento2 will create symlinks to the static files and you will not have to run the deploy command after each changed file, the deploy content command is for the Production enviornment – Vlad Patru Mar 30 '17 at 7:14
  • @VladPatru yeah thats i know. What about production? Why they do it? – Kingshuk Deb Mar 30 '17 at 7:23
3

"The main question is why magento2 has this feature?".

It is done this ways in order to have a fully Module design pattern.
In magento 1 the public assets (js, css, images) were placed in some public folders that reside outside the module itself.
For example: js, skin/frontend/...

In Magento 2 modules are actually modules. Everything related to a module goes in the module folder.
This includes public assets.
But the module folders should not be public for everyone.
So in order to make the public assets public you need to run static-content:deploy.
This will copy (or symlink) the public assets to a public folder.

Now if i would like to do some changes in those files then where i should do those changes? In the main file and again need to run the static-content:deploy command ? Or we can do in both places together.

You should never manually modify the files in the public folder. your changes will be overwritten the next time you run static-content:deploy.

This applies to the live environments also.
As a strategy to deploy, I'm not really sure about it.
You can pre-generate your static files somewhere else before deployment, then just move them when the deployment is done.
Or simply run static-content:deploy after your deployment. But this might make some users see something else for a few seconds that pass between the deployment and when the static files are generated.

0

The main reason for static files in magento I think is it speeds up website.

In Magento static view files are located in the /pub/static directory. Static view files deployment is affected by Magento modes. On production mode static files are not generated or cached. On Developer mode magento generates static files on demand. But for your question why magento2 has this feature? I think reason is it creates static files that speedup of access view files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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