I'm experiencing some odd behavior with the YouTube API when running my Nuxt website on Cloudflare Pages. On my VPS, everything works smoothly, loading hundreds of images and channel info without any issues. However, when I run the site on localhost or deploy it to Cloudflare Pages, I often have to refresh the page to see more images or details, and occasionally a hard refresh doesn't load anything at all. I'm unsure if the problem is linked to Cloudflare Pages or if it's a Nuxt-related issue. I even tried switching from NuxtImg to standard img tags, but that didn't help either. I suspect there may be something going on with rate limiting or aggressive caching since I've already purged the Cloudflare cache and checked that my YouTube API settings allow enough calls daily. Interestingly, nothing unusual shows up in the console. Any insights into why the API behaves differently on Cloudflare compared to my VPS setup?
4 Answers
It sounds like the edge network is playing a role here. Cloudflare Pages operates on Workers, which have their own caching per edge location. To get more consistent results, consider making your YouTube API calls server-side through a Nuxt server route instead of on the client side. That could help smooth things out!
If you're having issues on localhost too, it might not be something specific to Cloudflare. Sometimes the problem could be how requests are set up, like client-side request bursts, timing issues, or caching differences. Try putting your YouTube API calls behind a dedicated Nuxt server route and see if that resolves the inconsistencies.
Cloudflare Pages can have some issues with external API calls that just don’t pop up on typical VPS setups. The inconsistent loading you’re facing might be related to CF's edge caching or if you're hitting their request coalescing limits when making rapid calls to the YouTube API. You might want to experiment with adding cache-busting headers or introducing a delay between your API requests.
There are some quirks with Cloudflare Pages since they run on Workers, and yes, there are request limits and edge caching that might affect your YouTube API calls. You could be hitting subrequest limits. I use DigitalOcean's App Platform for my Nuxt apps and haven't run into these edge issues.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads