Why do browsers inefficiently make 2 requests here?

前端 未结 9 2164
-上瘾入骨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:34

    The browser will make the 2 requests on the page, cause an image called from the css uses a get request (not ajax) too before rendering the entire page.

    The window load is similar to de attribute, and is loading before the rest of the page, then, the image from the Ajax will be requested first than the image on the div, processed during the page load.

    If u would like to load a image after the entire page is loaded, u should use the document.ready() instead

提交回复
热议问题