Why do browsers inefficiently make 2 requests here?

前端 未结 9 2309
-上瘾入骨i
-上瘾入骨i 2021-02-13 14:48

I noticed something odd regarding ajax and image loading. Suppose you have an image on the page, and ajax requests the same image - one would guess that ajax requests would hit

9条回答
  •  天命终不由人
    2021-02-13 15:39

    Cache control on Ajax requests have always been a blurred and buggy subject (example). The problem gets even worse with cross-domain references.

    The fiddle link you provided is from jsfiddle.net which is an alias for fiddle.jshell.net. Every code runs inside the fiddle.jshell.net domain, but your code is referencing an image from the alias and browsers will consider it a cross-domain access.

    To fix it, you could change both urls to http://fiddle.jshell.net/img/logo-white.png or just /img/logo-white.png.

提交回复
热议问题