W
Wasp2w ago
xbp

static image reference in main.wasp

how do i reference static images in main.wasp? I want to populate the head property with some meta tags, that reference an image i have stored in app/src/client/static. i tried the below approach, but this did not work head: [ "<meta property='og:url' content='https://myapp.com/assets/image.png' />", ],
2 Replies
kapa.ai
kapa.ai2w ago
Hi @xbp. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To reference static images in your main.wasp file for meta tags, you need to understand how Wasp handles static assets. Based on the knowledge sources, there are two main approaches for handling static assets in Wasp: 1. Using the public directory:
The recommended approach for your use case is to place your image in the public directory at the root of your project. Assets in this directory are served at the root path / and copied to the dist directory as-is during build.
.
└── public
└── image.png

.
└── public
└── image.png

Then reference it in your main.wasp file like this:
head: [
"<meta property='og:url' content='<https://myapp.com/image.png'> />",
],

head: [
"<meta property='og:url' content='<https://myapp.com/image.png'> />",
],

Note that you should use the root absolute path (/image.png) rather than including assets/ in the path Static Assets - The Public Directory. 2. For assets that need to be imported in your code, you would typically place them in the src directory and import them, but this approach isn't suitable for static references in the head property of main.wasp. The issue with your current approach is that you're referencing /assets/image.png, but if your image is in app/src/client/static, it won't be automatically available at that URL. The /assets/ path is typically used for assets that are processed by the build system, not for directly referencing files. Currently, Wasp doesn't support dynamic environment-specific values in the head section of main.wasp. If you need environment-specific values, a workaround is to use React Helmet in your React components as suggested by the Wasp team in this Discord thread. For SEO purposes, having proper meta tags is important, and the Wasp team is aware of the need for better SEO support as mentioned in this GitHub issue. Hope this helps! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @xbp, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)2w ago
Hey @xbp did the bot solve your issue or do you need extra help? We're here if you need some human help 🙂

Did you find this page helpful?