I’m encountering a problem with relative paths when deploying my website via Vercel. For example, my site’s files are located at example.com/folder/index.html. Within this file, I reference an image in the same directory using ./img.jpg. However, after deploying the site, the image fails to load. The browser’s network tab shows the image path as example.com/img.jpg, even though the correct path should be example.com/folder/img.jpg based on the relative path.
This issue only occurs on Vercel. When testing locally, the image loads correctly. Additionally, deploying the same repository to GitHub Pages (e.g., username.github.io) also works as expected—the relative paths resolve properly. It seems Vercel is handling the path resolution differently.
Has anyone encountered similar behavior?
I build a test website on https://test1-pi-rosy.vercel.app, you can view the source code.
Hi @xrunes, thanks for explaining the problem. The link you shared shows both images correctly. Can you share an example where the images are not loaded correctly?
Also, I’d recommend using /folder/img.jp instead of ../ or ./ to ensure the browsers know the exact URL of the image relative to your root domain.