-
-
Notifications
You must be signed in to change notification settings - Fork 35
Description
🆒 Your use case
When configuring ogImage it would be great if there is somewhat more flexibility in how route queries are handled, or how cache keys are created.
Currently, any unique route query will create a new cache entry. But for most purposes, this not needed. (at least not in my case).
Let's say there is an og image cached for example.com/my-dynamic-page. When i request the route example.com/my-dynamic-page?foo=bar, the requested og image resource is
The existing cache is not hit, a new image will be rendered and cached thats identical to the original, except for the key it's stored under.
🆕 The solution you'd like
I'm aware that this might be exactly what you want, especially is the route query has an effect on the content for the og image. But for most of my projects, that is not the case.
I think the simplest solution would be to add a config option
ogImage: {
runtimeCacheStorage: {
// driver options
},
defaults: {
cacheMaxAgeSeconds: 60 * 60 * 24 * 7,
},
ignoreQuery: true,
zeroRuntime: false
}
Which should have the effect that the asset from my example would be requested at
https://example.com/__og-image__/image/my-dynamic-page/og.png, regardless of what query was used.
As an alternative, you could provided a getKey handler option, so we'd be able to fully customise the cache keys
🔍 Alternatives you've considered
I'm currently using this workaround in my server middleware
import { parseURL } from 'ufo'
export default defineEventHandler(async (event) => {
// Skip during prerendering
if (import.meta.prerender) return
const { pathname, search } = parseURL(event.path)
// Check if ogImage with query in pathname. If so, redirect to path without query
if (pathname.startsWith('/__og-image') && !!search) {
await sendRedirect(event, pathname, 301)
return
}
})
ℹ️ Additional info
No response