Symfony 3.3 - where should I put CSS and JS files?

721 views Asked by At

THIS link suggests that /app directory contains all configuration, templates (.html.twig files) and translations, and the /src directory contains PHP code.

However, HERE we can see that .css and .js files are loaded from /src/AppBundle/Resources/public directory and not /app/Resources/public directory. What is the best practice? How should I professionaly approach this problem, and where should I keep all the templates, .js and .css files?

2

There are 2 answers

0
zizoujab On BEST ANSWER

I like to put css and javascript that serve for general purposes in /app/Resources/public and the ones specific to the concerned bundle in /src/YourBundleNameBundle/Resources/public. Like that when I want to see a code specific for a bundle I will just go to that bundle , when it's a general purpose code I would be sure that it's in the root. I have seen expert people doing it and it makes sense for me.

It's a matter of choice and there is no right and wrong answer.

0
Akrem Boussaha On

the best practice is to put your css and js files in your bundle particularly in folder that you called "public" (yourBundle/Ressources/public/css/yourStyle.css) and make sure to run this command before

php bin/console assets:install

and To avoid typing this command each time, I recommend you make a link (a kind of shortcut), by adding the active parameter:

assets:install --symlink

So, the web /bundles/folderBundle actually points to src/yourBundle/Resources/public

On Windows, you must run the command prompt in administrator mode