Search code examples
vue.jsvue-cli

Vue.js - Why should I put images on /assets instead of putting them directly in /public


When I use the @vue/cli to create a vuejs project, I see that there is a folder /assets that contains images and whatever I want. Than they can be referenced in the html such as <img src="@/assets/images/home.png" /> or import it on the js part.

My question is, why can't I just put the assets in /public/assets and put directly <img src="/assets/images/home.png" /> in my code? Where is the advantage of these assets?


Solution

  • It allows Webpack to handle assets, which means it can merge/minify files (useful for JS and CSS), optimize images, and more importantly version them so that cache handling is improved.