Cloudflare Pages iPhone error: Invalid character '�'
Cloudflare Pages site blank on iPhone with "SyntaxError: Invalid character '�'"? How to confirm a zstd compression mismatch, and workarounds, likeliest first.
The Liite team7분 분량
Short answer
The error usually means Safari received a compressed JavaScript file it could not decode, and reports say the compression was zstd. First confirm it with curl, then stop Cloudflare from using zstd for your site (a compression rule), or serve the site some other way (Workers static assets). Switching Vite's minifier to terser is a reported workaround, but nobody knows why it works.
Your Cloudflare Pages site loads on desktop, but on an iPhone the page is blank or half-drawn, and the Safari console says:
SyntaxError: Invalid character '�'
Why it happens
The � is the Unicode replacement character. It appears when a parser reads bytes that aren't valid text. In this case the JavaScript file reached Safari still compressed, so the parser choked on the first bytes.
The causes, most likely first:
- Zstandard (zstd) responses that iOS Safari can't decode. People on Cloudflare's community forum and on Reddit reported this in April 2025 for Pages sites on iOS. Cloudflare's docs say that on the Free plan, content is compressed by default using Zstandard, so a Free-plan site meets zstd more often. The docs also say the actual compression applied may depend on what the visitor's browser requests via the accept-encoding header.
- A mismatch between what the browser advertised and what the server sent. A server names its choice in the
Content-Encodingheader. Whether a server uses the compression methods a client requests depends on server configuration and capabilities. If a response arrives in an encoding the browser can't decode, you get this kind of garbage. - Something unrelated that happens to touch compression. Cloudflare's changelog from late November 2026 describes a fix for range requests. Previously, a client that did not accept the encoding could receive a 206 Partial Content response whose bytes did not match its Content-Range header. That concerns range requests, which is not the usual way a browser loads a script, so don't assume it is your cause.
What we don't know: which iOS versions are affected, whether Cloudflare has fixed the Pages behavior since the 2025 reports, and why the terser workaround helps. We haven't reproduced it. Treat the zstd theory as the best lead, not a certain diagnosis.
How to confirm it is a compression problem
Do this before changing anything.
- Open the site on a desktop browser and on the iPhone. If it works on desktop but fails only on iOS, that fits the reports.
- Connect the iPhone to a Mac and open Safari's Web Inspector from the Develop menu. Read the console error and note which file fails.
- Request that file with curl, once offering zstd and once not. Use your own URL:
curl -sI -H "Accept-Encoding: gzip, br, zstd" https://your-site.pages.dev/assets/index.js
curl -sI -H "Accept-Encoding: gzip, br" https://your-site.pages.dev/assets/index.js- Compare the
content-encodingheader in each response. A typical browser navigation sends gzip, deflate, br, zstd, so the first command is the normal case.
| What you see | What it suggests |
|---|---|
content-encoding: zstd with zstd offered, br or gzip without it | Normal negotiation. The server is behaving; the problem may be in Safari's handling. |
content-encoding: zstd even when zstd is not offered | The server ignores the request header. This is the clearest sign of a server-side bug. |
No content-encoding at all | Compression isn't the cause. Look at your build or cache. |
Note that curl cannot tell you what a given iPhone sends. The Web Inspector's Network tab can show the request and response headers for the failing file.
Step-by-step fixes
Fix 1: Control which compression Cloudflare uses
Cloudflare's Compression Rules let you choose the algorithm. The docs describe a custom option with Gzip, Brotli and Zstandard choices, each used if the visitor supports it. The goal is to leave zstd out.
- In the Cloudflare dashboard, open the zone that serves your site and find Rules and then Compression Rules.
- Create a rule that matches the JavaScript, CSS and HTML responses (for example by media type).
- Choose Custom and list Brotli and Gzip, without Zstandard.
- Add Auto at the end. The docs warn that if you specify only Gzip, Brotli or Zstandard and none match, the response has no compression, and adding Auto gives you a fallback.
- Save, then purge the cache for the affected files if they are cached.
Two limits. People in the original thread said compression rules aren't available on the free plan, and we couldn't confirm the current plan rules from the docs we found, so check your own dashboard. Also, a rule belongs to a zone, so as far as we know it can only affect a custom domain you've added, not the *.pages.dev address.
Fix 2: Serve the files from Workers static assets
People in the thread reported that serving the same files through Workers static assets avoided the error. Follow Cloudflare's current developer docs for the migration, because the tooling has changed over time. Test on an iPhone after the move; we haven't confirmed that this fixes it in every case.
Fix 3: Switch Vite's minifier to terser
If you build with Vite, people reported that setting the minifier to terser made the error go away. Install terser first, since Vite doesn't bundle it:
npm install -D terserThen set it in your Vite config:
export default {
build: {
minify: "terser",
},
};Not a root-cause fix
We don't know why this helps, and it doesn't change how Cloudflare compresses the file. It may only change which bytes trip up the decoder. Use it as a stopgap and keep checking the headers.
After any change
Redeploy, then test on a real iPhone in a private tab, or clear Safari's website data for the site first. A cached broken file can make a working fix look like a failure.
What won't help
- Clearing site data on one phone. It may work once, but every other iPhone visitor still gets the same response.
- Debugging your own JavaScript. The code isn't the problem. The file arrives in a form Safari can't read.
- Redeploying the same build. The files and the compression behavior stay the same.
- Asking visitors to update iOS. You can't control it, and we can't say which versions are affected.
Checklist before you try again
- The error appears only on iOS, and the same URL works on desktop.
- You have read
content-encodingfor the failing file with and withoutzstdoffered. - Any compression rule excludes zstd and ends with Auto.
- You purged the cache for the affected files after changing the rule.
- You tested in a private tab on a real iPhone, not only a desktop simulator.
If nothing works
Ask Cloudflare. Use the Cloudflare Community forum or, on a paid plan, Cloudflare support. Include the exact error text, the URL of the failing file, the curl output for both requests, your plan, whether you use a custom domain, the iOS and Safari versions, and when it started. Something like:
Subject: Pages site fails on iOS Safari: SyntaxError: Invalid character '�'
My Cloudflare Pages site (https://your-site.pages.dev) loads on desktop
but fails on iPhone (iOS <version>, Safari) with:
SyntaxError: Invalid character '�'
The failing file is /assets/index.js. I suspect a zstd Content-Encoding
issue. curl output with "Accept-Encoding: gzip, br, zstd" and with
"Accept-Encoding: gzip, br" is attached, with timestamps (UTC).
Plan: <Free/Pro/...>. Custom domain: <yes/no>.
Steps tried: <compression rule, terser, ...>
Can you confirm which encoding is sent to this client and why?Common questions
Does this affect Android or desktop browsers?
The reports describe iOS Safari only. If the same files load on desktop and Android, that matches what people said.
Is the bug fixed now?
We don't know. The reports we found date from April 2025, and nothing we found confirms a fix. Run the curl checks and an iPhone test on your own site.
Why would zstd be sent at all?
Cloudflare's docs say the Free plan is compressed with zstd by default, and customers can enable Zstandard through Compression Rules. Zstd is a valid encoding, and it is defined in RFC 8878. The trouble is only when a client can't decode what it receives.
Will terser change my output?
It minifies your JavaScript differently, so file sizes may differ a little. Compare your build output before and after if bundle size matters.