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.
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:
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.