Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

504
Views
Do I store Image assets in public or src in reactJS?

I am using react for my application. I have a div that I would like to have a background image. But I can't get it to show.

When I include it in the src folder as myapp/src/bgimage.png it works perfectly but I've heard that I should include it in a folder named images at the root level so it's myapp/images/bgimage.png, however this does not work for me and gives me:

You attempted to import ../images/bgimage.png which falls outside of the project src/ directory.'

Can anyone tell me the proper way to include image assets in reactJS?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

public: anything that is not used by your app when it compiles

src: anything that is used when the app is compiled

So for example if you use an image inside a component, it should be in the src folder but if you have an image outside the app (i.e. favicon) it should be in public.

over 4 years ago · Santiago Trujillo Report

0

I would add that creating an "assets" folder inside the "src" folder is a good practice.

over 4 years ago · Santiago Trujillo Report

0

Use /src if you are using create-react-app


If you are using create-react-app, You need to use /src for the following benefits.

  1. Scripts and stylesheets get minified and bundled together to avoid extra network requests.
  2. Missing files cause compilation errors instead of 404 errors for your users.
  3. Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.

Also, if you are using webpack's asset bundling anyway, then your files in /src will be rebuilt.

You may create subdirectories inside src. For faster rebuilds, only files inside src are processed by webpack. You need to put any JS and CSS files inside src, otherwise webpack won’t see them.

See this link

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!