NFT Media Caching: How Alchemy Optimizes Media Delivery?
NFT media, such as images and videos, are often hosted on decentralized platforms like IPFS or third-party servers. However, this can result in slow loading times and occasional errors. To address these issues, Alchemy caches NFT media, providing faster and more reliable access through our CDN. In this article, we explain how Alchemy’s media caching works and how to use it for optimizing your NFT applications.
Why does Alchemy cache NFT media?
NFT media is typically hosted on IPFS or third-party servers, which can result in slow load times or timeout errors, especially when these endpoints experience high traffic. To enhance the user experience and reduce these issues, Alchemy caches NFT media and serves cached media URLs directly from its own CDN (Content Delivery Network). This ensures faster load times and more reliable access to NFT assets.
How do I use Alchemy-hosted NFT media?
When available, Alchemy automatically replaces the default gateway
field in the NFT media
object with an Alchemy NFT-CDN URL. This URL points to the cached version of the media, improving the loading speed and reliability.
• Alchemy-hosted NFT Asset:
• Third-party hosted NFT Asset:
Here’s an example of a BAYC (Bored Ape Yacht Club) NFT asset cached by Alchemy:
https://nft-cdn.alchemy.com/eth-mainnet/d9d674adddb2da8fcbcdb0230ca1da3d
Why did my request not return a cached media URL?
While Alchemy is working on expanding its coverage of hosted NFT media, there may be instances where the requested NFT does not yet have a cached URL available. This is part of our ongoing efforts to increase our cache network for NFTs across all networks.
Which media URL should I use to display NFT images?
To ensure the best performance and reliability when displaying NFT media, Alchemy recommends using the following media URL hierarchy:
1. media.gateway: This is the preferred URL, which points to the Alchemy-hosted CDN if available.
2. media.raw: If the gateway URL is not available, fallback to this URL, which may point to third-party or IPFS sources.
3. metadata.image: If neither of the above URLs is available, use the image provided in the metadata object.
Following this order ensures that you’re always serving the fastest and most reliable media available for NFTs.