CSS and JS issues when deploying Sitecore XM Cloud to Vercel

CSS and JS issues when deploying Sitecore XM Cloud to Vercel

By admin August 7, 2024

When I first started working with XM Cloud and Vercel, I quickly realized how much there was to learn, especially when it came to the specifics of deployment and environment configurations. I followed the official documentation to set up my site and configured Vercel for deployment, but I encountered a frustrating issue: the theme — both the CSS and JavaScript files — wasn’t loading correctly on the user interface. The site looked broken, with no styles or scripts applied, making it impossible to move forward.

After spending some time troubleshooting and scouring the internet for solutions, I came across a very helpful and detailed blog post. It outlined several common pitfalls with deploying to Vercel and how to address them. The problem I was facing was that the assets weren't loading because the PUBLIC_URL environment variable hadn't been set properly.

The solution turned out to be simple but effective: I needed to set the PUBLIC_URL environment variable in Vercel and point it to the production deployment URL. Once I made that change, the issue was resolved, and both the CSS and JavaScript files started loading correctly, restoring the site's appearance and functionality.

This experience highlighted the importance of understanding how environment variables like PUBLIC_URL work in cloud deployments and how they directly affect asset loading, especially when working with tools like Vercel.

Featured Blogs