OGImage not showing

I am trying to display a dynamic image for SEO based on the page being viewed. The page loads a different item image accordingly. To achieve this, I am using the useSeoMeta composable and setting the URL to the image with a computed property or a ref. It shows the correct URL in the HTML inspector, but it does not load, for example, in Discord
No description
No description
No description
No description
No description
40 Replies
Single
Single8mo ago
Be aware, that most platforms, including Discord are caching the og:images heavily. Thus unless the url of the image changes, you have to wait. I assume your url changes with every image. Have you tried to test with https://opengraph.dev ?
opengraph
OpenGraph - Preview Images and Generate Open Graph Meta Tags
OpenGraph.Dev: Generate and preview Open Graph meta tags for images, titles, and more, ensuring optimal display on Facebook, Twitter, LinkedIn, WhatsApp...
Luckystriike
LuckystriikeOP8mo ago
ow for real? damn works with this preview Thanks!!
Single
Single8mo ago
Append a ?timestamp=Date.now() and you might be good
Luckystriike
LuckystriikeOP8mo ago
wow you are the best! will try ow let me test first 😛 because it tried with a hardcoded image url now 😛 where do i add a timestamp? @Single just somewhere in the description?
Single
Single8mo ago
In your computed:
ogImage: () => config.public.BASEURI +"/Icons/"+item.value?.icon + "?timestamp="+ Date.now()
ogImage: () => config.public.BASEURI +"/Icons/"+item.value?.icon + "?timestamp="+ Date.now()
Luckystriike
LuckystriikeOP8mo ago
oke will try thanks i'll let you know once the test env is published because i cannot test it locally right?
Single
Single8mo ago
ogImage: () => `${config.public.BASEURI}/Icons/${item.value?.icon}?timestamp=${Date.now()}`
ogImage: () => `${config.public.BASEURI}/Icons/${item.value?.icon}?timestamp=${Date.now()}`
This would be a more readable solution, using template literals
Luckystriike
LuckystriikeOP8mo ago
nope sorry! with the computed prop the image is undefined damn
Luckystriike
LuckystriikeOP8mo ago
@Single
No description
Luckystriike
LuckystriikeOP8mo ago
so it works with a hardcoded url but not with a compuited
Single
Single8mo ago
Can you check for typos? I had to write the text according to your image
Luckystriike
LuckystriikeOP8mo ago
indeed let me recheck it all
Single
Single8mo ago
Test locally if the url is correct before you deploy
Luckystriike
LuckystriikeOP8mo ago
it has the correct url in the hteml head
Luckystriike
LuckystriikeOP8mo ago
No description
Luckystriike
LuckystriikeOP8mo ago
so after fully loading the page it has the correct url
Single
Single8mo ago
Good And does it work in opengraph.dev?
Luckystriike
LuckystriikeOP8mo ago
nope still undefined 😛 could it be the computed stuff loading to slow
Single
Single8mo ago
Does the url work in your local browser?
Luckystriike
LuckystriikeOP8mo ago
yeah
Single
Single8mo ago
Ok, so its not my change but a different problem Does the page need authentication by any chance?
Luckystriike
LuckystriikeOP8mo ago
nope
Single
Single8mo ago
Do you use ssr?
Luckystriike
LuckystriikeOP8mo ago
Don't know how do i check this 😛
Single
Single8mo ago
If you did not disable it by adding ssr: false to your nuxt config it should be enabled
Luckystriike
LuckystriikeOP8mo ago
ssr would be better?
Single
Single8mo ago
Depends on the page but the general idea is yes
Luckystriike
LuckystriikeOP8mo ago
oke well if by default it is enabled
Single
Single8mo ago
If you hardcode the url, its working i guess?
Luckystriike
LuckystriikeOP8mo ago
yeah
Single
Single8mo ago
I assume the page meta is generated at buildtime, not at runtime. I am not entirely sure here. Let me make a test and get back to you later. Seems like is working Is item.value?.icon undefined maybe?
Luckystriike
LuckystriikeOP8mo ago
in the seo preview it is but in the html view not but item.value is also loaded after mounted in onMounted
Single
Single8mo ago
That might be too late
Luckystriike
LuckystriikeOP8mo ago
yeah mhh let me check if there is another way :p ow it is in the onbeforeMounted @Single Cool did a total rewrite and moved the init item outside the mounted function. Now it seems to work 💪
Single
Single8mo ago
Nice! Glad you made it! I thing we were talking next to each other earlier. If you image url DOES change, there is no need to use ?timestamp=... You would only want to append this in case your url stays the same but the image being served has different content.
Luckystriike
LuckystriikeOP8mo ago
Oke cool! will try thanks for your help
hz2222
hz22226mo ago
How did u achive this? I am working on a similar problem
Luckystriike
LuckystriikeOP6mo ago
Did something like this “ const config = useRuntimeConfig(); // data const item = ref<Equipment | null>(null); useSeoMeta({ ogTitle: () => ${item.value?.name} - Luckys crafting site, ogImage: () => ${config.public.BASEURI}/Icons/${item.value?.icon} + "?timestamp=" + Date.now(), ogDescription: () => { var string = ""; item.value?.materials.forEach(i => { string += ${i.amount}x ${i.name}, }) return string; }, ogImageWidth: 80, ogImageHeight: 80 })” And in the nuxt config “runtimeConfig: { public: { DEBUG: process.env.DEBUG, ENCODERSTRING: process.env.ENCODERSTRING, ENCODERNUMBER: process.env.ENCODERNUMBER, BASEURI: process.env.NUXT_PUBLIC_BASEURI },”
hz2222
hz22226mo ago
Thx , but how do you fetching the data for the seo? With asyncData?
Luckystriike
LuckystriikeOP6mo ago
With useFetch in the setup so the created
Want results from more Discord servers?
Add your server