Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermittent failure to load images - ERR_CONTENT_LENGTH_MISMATCH

The problem

My website fails to load random images at random times. Intermittent failure to load image with the following error in console:

"GET example.com/image.jpg net::ERR_CONTENT_LENGTH_MISMATCH"

Image either doesn't load at all and gives the broken image icon with alt tag, or it loads halfway and the rest is corrupted (e.g. colors all screwed up or half the image will be greyed out).

Setup

Litespeed server, PHP/mySQL website, with HTML, CSS, Javascript, and JQuery.

Important Notes

  • Problem occurs on all major web browsers - intermittently and with various images.
  • I am forcing UTF-8 encoding and HTTPS on all pages via htaccess.
  • Hosting provider states that all permissions are set correctly.
  • In my access log, when an image fails to load, it gives a '200 OK' response for the image and lists the bytes transferred as '0' (zero).
  • It is almost always images that fail to load but maybe 5% of the time it will be a CSS file or Javascript file.
  • Problem occurred immediately after moving servers from Apache to Litespeed and has been persistent over several weeks.
  • Gzip and caching enabled.
like image 518
user3100907 Avatar asked Jun 13 '15 15:06

user3100907


1 Answers

This error is definite mismatch between the data that is advertised in the HTTP Headers and the data transferred over the wire.

It could come from the following:

  1. Server : If a server has a bug with certain modules that changes the content but don't update the content-length in the header or just doesn't work properly.
  2. Proxy : Any proxy between you and your server could be modifying the request and not update the content-length header.

This could also happens if setting wrong content-type.

As far as I know, I haven't see those problem in IIS/apache/tomcat but mostly with custom written code. (Writing image yourself on the response stream)

It could be even caused by your ad blocker.

Try to disable it or adding an exception for the domain from which the images come from.

like image 82
Zahid Riaz Avatar answered Oct 04 '22 03:10

Zahid Riaz