Hi Tiago, one benefit of importing images using import statements is that you can have a bundler like vite or webpack optimize the images, then spit them out to an output folder. Importing images also creates immutable data types so the path isn't accidentally changed at some point within your code.
The downside is you have quite a few more lines of code importing variables compared to just assigning the image location to an
image.src object directly.
Both methods work, but the import statement version is mostly used within web apps since they don't allow for the traditional method (doesn't work with web app bundlers).
Hope that makes sense and helps a bit.
Hi! Thank you so much for your answer, it helped me a lot :) I just have another question.
I wanted to have some information in my website so I added some signboards along the background. Is it possible to make those signboards clickable? I wanted to have a pop-up with the info showing up when the signboard was clicked.
If not, is there some alternative? I really need to have some information on the website.
Thank you once again.
Have a good day :)
Want to participate?
Create a free Chris Courses account to begin