Where to put images in React: public/ or src/assets/

🧠 Sunday Brainstorm — The Confusion Every React Developer Has: Public vs Src for Images Happy Sunday, everyone 👋 Since I’ve been posting my #30DaysOfNextJS updates on alternate days, today I wanted to talk about something outside the series — but something every frontend dev faces when they start working on real-world projects: 👉 Where should we put our images? public/ or src/assets/? When we’re learning React, we usually throw everything inside the public folder. But the moment we enter an actual company… suddenly there’s a whole assets folder inside src and everything is imported instead of directly referenced. So which is the right way? I recently read a Medium post about this, and honestly — it finally clicked. Here’s a simple version in my own words 👇 📁 Public Folder — Best for Static, Rarely-Changing Assets Use public/ when your assets are: ✔ Static ✔ Large ✔ Rarely modified Why? ⚡ Served directly by the browser → faster 🔄 You don’t need to rebuild the app when they change 📁 No imports needed But… ❗ Not optimized by Webpack ❗ Fully exposed to the public ❗ Larger file sizes if not optimized Usage: <img src="/banner.png" /> 📁 Src/Assets — Best for Component-Driven Assets Use src/assets/ when your assets are: ✔ Part of UI ✔ Used inside components ✔ Dynamic or reused Why? 🛡 More secure 📦 Webpack optimizes images (compression, hashing, cache-busting) ♻ Can be reused across components But… ⚠ Needs import statements ⚠ Triggers a rebuild when changed ⚠ Slightly more complex Usage: import banner from "../assets/banner.png"; <img src={banner} /> 🔍 My Conclusion (and what most companies follow): Use both, smartly: 🔸 public/ → large static assets that rarely change 🔸 src/assets/ → component-based images & reusable UI assets It gives you the best balance of performance, flexibility, and maintainability. Also adding the medium link from where I cleared my doubt 👇 https://lnkd.in/gFnbYi5y #React #WebDevelopment #Frontend #JavaScript #ReactJS #CodeNewbie #FrontendTips #LearningInPublic #NextJS #DeveloperLife #SundayPost #DevCommunity

  • table

To view or add a comment, sign in

Explore content categories