Atlaslog
Atlaslog / Field Notes / Tiles
Field note · Tiles

Tiles return 204 instead of 404, leaving invisible white gaps

Quick answer

The tile service answers `204 No Content` outside its data extent, which the browser treats as a successful load. The area renders as transparent white with no grey block and no `tileerror`, so monitoring reports everything healthy.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet 1.9.x / OpenLayers 9.x / Nginx 1.20+
Symptom
Checklist
  1. Filter the network panel by status 204, or by 200 responses with a 0-byte body
  2. Inspect `Content-Type` and `Content-Length` on the tile response
  3. Log `e.tile.naturalWidth` inside `tileload` to catch zero-size images
  4. Check the tile server's documented empty-tile policy: 204, transparent PNG, or 404
  5. Reproduce with a coordinate well outside coverage
Fix

Make the server return 404 for missing tiles (`try_files $uri =404`) so the client can react, or return a 1x1 transparent PNG; on the client, count `tileload` events with `naturalWidth === 0` and show a no-data hint after a few.

Code
layer.on('tileload', e => {
  if (e.tile.naturalWidth === 0) console.warn('空瓦片', e.coords, e.tile.src);
});
// 204 的瓦片会打出警告,而 tileerror 不会触发
# Nginx:空目录不再返回 204,而是 404
location /tiles/ {
  try_files $uri =404;
}

# 若希望缺图时不破坏画面,返回 1×1 透明 PNG
location /tiles/ {
  try_files $uri /blank.png;
  add_header Cache-Control "public, max-age=86400";
}
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Tiles return 204 instead of 404, leaving invisible white gaps. https://www.jingweizhi.com/en/cookbook/tile-204-blank.html (accessed 2026-11-03).