I’m dealing with a frustrating problem where Google Docs viewer embedded in an iframe works most of the time but randomly fails to show PDF files. This intermittent behavior is driving me crazy because I can’t figure out what’s causing it.
Here’s what happens when I test it:
My setup: Simple HTML page with a heading and iframe that points to a PDF file hosted on my server
The problem: The PDF shows up correctly about 60% of the time, but fails randomly on other attempts
What I noticed: When I refresh the page multiple times (around 10 refreshes), it will definitely fail at least once. The network response shows a 307 redirect first (this happens when it works too), but then I get a 204 no content response instead of the expected 200 with actual content.
I’ve tested this on Chrome version 48 and Microsoft Edge version 25, and both browsers show the exact same failure rate and behavior. There are no visible JavaScript errors or console messages that would help me debug this.
Has anyone encountered similar reliability issues with Google Docs viewer? What could cause this random failure pattern?
Yeah, I’ve hit this exact issue - super frustrating. That 60% success rate definitely points to Google’s server-side caching being wonky. Try adding a random query parameter to your iframe src like &v=${Date.now()}. Forces Google to treat each request as fresh instead of serving from their unreliable cache.
You’re hitting Google’s rate limits. Had the same issue last year embedding multiple PDFs on a client site. That 307 redirect then 204 no content? Classic Google throttling. Here’s what fixed it for me: add a local caching layer. Don’t link directly to Google Docs viewer each time - cache the viewer response server-side for a few hours. Cut my requests to Google massively and killed those random failures. Or try PDF.js as backup. Detect when Google’s viewer craps out and auto-switch to PDF.js. Not as pretty as Google’s but rock solid since you’re hosting it yourself.
Yeah, this is a classic Google viewer issue. Hit the same problem two years back while building a doc management system. Google’s viewer has crappy load balancing - sometimes your request hits an overloaded server or one that’s just down. Here’s what fixed it for me: add a retry with exponential backoff. When the iframe craps out (catch it with onload), wait 2 seconds and try reloading the same URL. Still broken? Wait 4 seconds, then 8. Usually works on the first retry. Also check your PDF size - anything over 25MB fails way more often. I’d add a fallback to direct PDF download when the viewer keeps failing. Users would rather download than stare at a blank iframe.