3

in laravel, which one is the proper way to add custom css & js files:

  • in public folder
  • in resource folder

I added my custom css/js files in resource folder but not working. But it works when I added my css and js files in public folder. Need a proper way to do that.

1 Answer 1

4

You can either:

  1. Drag/drop them in the /public directory

  2. Place the file in the /resources directory, and in your build tool, copy the file(s)/directory(ies) from /resources to /public

If you use #1, be sure to add/include it the file(s) in your VCS.

Laravel has documentation on #2: https://laravel.com/docs/5.6/mix#copying-files-and-directories

Sign up to request clarification or add additional context in comments.

2 Comments

that means if I want to add a custom css file like style.css in my laravel project then it is better to put that css file in both public and resource directory. i.e, public/css/style.css, resources/assets/css/style.css
There's no need to add it to both, one or the other would work. I have always used #2, so placed the custom css file in my resources/css folder and then @import ../css/<file>.css in my SASS (or, converted it to a SASS file). Or, you could place the file in resources/css, and then just copy it to /public/css` and then link to it as normal (/css/<file>.css) in your HTML

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.