Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH

JavascriptJqueryImageGoogle Chrome

Javascript Problem Overview


What does this error message mean and how do I resolve it? That is from console of Google Chrome v33.0, on Windows 7.

> Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH           http://and.img.url/here.png

I'm trying to change the images' src attribute using jQuery. For example like this (simplified):

$('.image-prld').attr('src', someDynamicValue);

There are about 30 images on the page. And the above error is happening for random images every time when I reload the page. But sometimes it is working well for all the images, without any error.

When this error happens, the particular image is displaying like this:

enter image description here

However, when I open the link next to the error message on a new tab, the image is loading, which says me logically that the images is valid and it exists.

Javascript Solutions


Solution 1 - Javascript

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. It was the case for the Node HTTP Proxy at some point (see here)

  2. Proxy: Any proxy between you and your server could be modifying the request and not update the content-length header.

As far as I know, I haven't see those problem in IIS but mostly with custom written code.

Let me know if that helps.

Solution 2 - Javascript

Docker + NGINX

In my situation, the problem was nginx docker container disk space. I had 10GB of logs and when I reduce this amount it works.

Step by step (for rookies/newbies)

  1. Enter in your container: docker exec -it <container_id> bash

  2. Go to your logs, for example: cd /var/log/nginx.

  3. [optional] Show file size: ls -lh for individual file size or du -h for folder size.

  4. Empty file(s) with > file_name.

  5. It works!.

For advanced developers/sysadmins

Empty your nginx log with > file_name or similar.

Hope it helps

Solution 3 - Javascript

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.

Solution 4 - Javascript

This can be caused by a full disk (Ubuntu/Nginx).

My situation:

Solution 5 - Javascript

In my case I was miscalculating the Content-Length that I advertised in the header. I was serving Range-Requests for files and I mistakenly published the filesize in Content-Length.

I fixed the problem by setting Content-Length to the actual range that I was sending back to the browser.

So in case I am answering to a normal request I set the Content-Length to the filesize. In case I am answering to a range-request I set the Content-Length to the actualy length of the requested range.

Solution 6 - Javascript

In my case I was modifying the request to append a header (using Fiddler) to an https request, but I did not configure it to decrypt https traffic. You can export a manually-created certificate from Fiddler, so you can trust/import the certificate by your browsers. See above link for details, some steps include:

  1. Click Tools > Fiddler Options.
  2. Click the HTTPS tab. Ensure the Decrypt HTTPS traffic checkbox is checked.
  3. Click the Export Fiddler Root Certificate to Desktop button.

Solution 7 - Javascript

This is what worked for me.

		proxy_buffer_size   1M;
		proxy_buffers   4 1M;

I increased the size of the above parameters in nginix proxy.conf file. Here, nginix is working as a proxy for my microservice-based applications.

Solution 8 - Javascript

In my case it was a proxy issue (requests proxied from nginx to a varnish cache) that caused the issue. I needed to add the following to my proxy definition

        proxy_set_header Connection keep-alive; 

I found the answer here: https://stackoverflow.com/a/55341260/1062129

Solution 9 - Javascript

If this is related to docker, try stopping the erroneous container and starting a new container using docker run command from the same image.

Solution 10 - Javascript

If anyone struggle with that problem using docker + nginx, it could be permissions. Nginx logs shown error:

2019/12/16 08:54:58 [crit] 6#6: *23 open() "/var/tmp/nginx/fastcgi/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: 172.24.0.2, server: test.loc, request: "GET /login HTTP/1.1", upstream: "fastcgi://172.28.0.2:9001", host: "test.loc"

Run inside nginx container(path might vary):

chown -R www-data:www-data /var/tmp/nginx/

Solution 11 - Javascript

Running docker system prune -a did the trick for me. I did not have any luck rebuilding my containers or following @mrroot5's answer, although those would seem to achieve similar things.

Solution 12 - Javascript

It is definitely has to do something with disk space on your server clearing the log folder worked for me. follow these steps

1. go to nginx log directory
   cd /var/log/nginx
2. delete all the older log
   rm *.gz               
3. emplty error log
   truncate -s 0 error.log.1 
4. empty access log
   truncate -s 0 access.log.1

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3332579View Question on Stackoverflow
Solution 1 - JavascriptMaxime RouillerView Answer on Stackoverflow
Solution 2 - Javascriptmrroot5View Answer on Stackoverflow
Solution 3 - JavascriptJoe ValerianaView Answer on Stackoverflow
Solution 4 - JavascriptvdBView Answer on Stackoverflow
Solution 5 - JavascriptTobias GassmannView Answer on Stackoverflow
Solution 6 - JavascriptThe Red PeaView Answer on Stackoverflow
Solution 7 - JavascriptGitesh kumar JhaView Answer on Stackoverflow
Solution 8 - JavascriptGeorgeView Answer on Stackoverflow
Solution 9 - JavascriptLanil MarasingheView Answer on Stackoverflow
Solution 10 - JavascriptBiegaczView Answer on Stackoverflow
Solution 11 - Javascriptambe5960View Answer on Stackoverflow
Solution 12 - Javascriptshyam yadavView Answer on Stackoverflow