-
-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve status image quality #391
base: main
Are you sure you want to change the base?
feat: improve status image quality #391
Conversation
Run & review this pull request in StackBlitz Codeflow. |
✅ Deploy Preview for elk-zone ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@Shinigami92 is the cache really necessary? I think that og-images should already be returning with proper cache headers and we can let the browser do this work. I think we shouldn't need to deal with this on our side 🤔 |
We have two options:
The solution I implemented fetches the WHOLE html content and then extract the og:image from it (if it exists) |
mmm... I misunderstood what the cache was for. Ok, this now makes more sense, although I don't know if we want this kind of logic in the server. Leaving this one to @danielroe to asses, but this may not scale. It is a pity but maybe we should change the way we do our previews to have smaller social images somehow to use the social image infra of Mastodon servers 🤔 Or maybe the original image is cached too? I don't see the API in their docs though. Looks like only this size is cached by the servers. |
I already searched like an hour for alternative bigger images in the cache, and I found nothing |
Ya, I see. IMO we should still use the social images infra that Mastodon servers provide and:
|
I'm slightly against this as these thumbnails holds usually much more info then just a logo It is impossible to create thumbnails for all kind of sites without asking concrete informations Let's wait on @danielroe and I hope he sees the value in this cached solution that already works great |
For the record, I see the value and would love to have full resolution social images but if it would be just a matter of a memory cache, the Mastodon server would already be doing this. Twitter also has strong caching of social images. |
Here is another not GitHub example where I can clearly spot a difference in image quality https://elk.zone/mas.to/@[email protected]/109496256426369984 Extracts <meta content="https://pbs.twimg.com/media/FjtXVhIX0AEZfle.jpg:large" property="og:image" data-rh="true"> And another example: https://elk.zone/mas.to/@[email protected]/109500354824115624 luckily both these examples have reposted the image itself, but this is not always the case and therefore not the point here for these examples Okay here is now an extreme example: https://elk.zone/mas.to/@[email protected]/109500422454039277 Mastodon: https://media.mas.to/masto-public/cache/preview_cards/images/014/199/635/original/c816ebf180bc7d69.png How in the world could someone resolve |
The current solution does not work for examples like Twitter that async loads |
Eh, I was thinking of how it's nice that some services like Signal and vanilla Mastodon only request the og image once, via the author in Signal's case & via the homeserver in Mastodon's case. The nice thing is this prevents following people from causing you to make requests to exterior sites, which could be a privacy vector similar to facebook tracking pixel for example, ++ then servers aren't getting N og image requests per client loading the post |
@ayoayco @jasikpark But I already use caching strategies as most as I can I'm assuming that Twitter makes a lot more such requests than mastodon and elk combined |
server/api/og-image/[url].ts
Outdated
return | ||
} | ||
|
||
await sendRedirect(event, ogImageUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main issue is that by sending a redirect we are opting-out of the netlify built assets cache. pushing something to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But fetching all the images and caching them on netlify is non goal and something I specially wanted to omit from the start
All these og:image out there in the world are already exactly provided to be shown via social media, are they?
So why do we need to copy images and store them again on our side? IMO this is just duplicating and waste of carbon footprint.
Whereas the first solution I had with the in memory cache worked totally find but just was one hop more to our internal api
Why do we not cache public status posts or account but every client ask the mastodon api individually? This is okay but the in memory internal server side cache is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Yes, I see that. It's tricky, but firing up a lambda to respond to a request is also quite costly compared to CDN cache. We could cache a JSON response with the URL to the image instead.
But, on the other hand, that way we have eagerly request rather than relying on browser + srcset 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Yes, I see that. It's tricky, but firing up a lambda to respond to a request is also quite costly compared to CDN cache. We could cache a JSON response with the URL to the image instead.
But, on the other hand, that way we have eagerly request rather than relying on browser + srcset 🤔
A benefit would be, we can enhance it later with more tags like og:title, og:image:alt and og:description (if needed)
I think the on-demand loading could be solved via virtual scrolling and/or Intersection Observer
Removed opengraph integration for now as the 100 req / mo limit was very low and it became costly. I'm still worrked about usage; the consequence would be what appears to be sluggish image loading, and huge usage on netlify serverless functions. It might be better to perform selective enhancement for known domains (like |
Opened an issue at Mastodon: mastodon/mastodon#22268 |
Generally, I would suggest avoiding putting server-side logic into Elk as much as possible. As it increases the load exponentially as the user base grows. I agree it's better to be handled on Mastodon side instead. |
I wasn't aware that all server side code inside Nuxt's I put this PR on hold for now and we will see what Mastodon will do. |
Thanks @Shinigami92! I think you did good exploration here. In #413 @LittleSound also got in some code change to not stretch smaller images. I'm wanna check next if native dimensions (i think 400x200) will look okay for bigger ones |
Improves the image quality of status preview cards by fetching async behind the background server and calls the underlying website and extracts the
og:image
meta-propertythen caches it and keep it in memory until not relevant anymore
tip: open both images and compare by switching tabs back and forth