Why serve 1x1 pixel GIF (web bugs) data at all?

前端 未结 8 1305
名媛妹妹
名媛妹妹 2020-12-12 09:44

Many analytic and tracking tools are requesting 1x1 GIF image (web bug, invisible for the user) for cross-domain event storing/processing.

Why to serve this GIF i

8条回答
  •  自闭症患者
    2020-12-12 09:51

    This is to answer the OP's question - "why to serve GIF image data..."

    Some users will put a simple img tag to call your event logging service -

    
    

    In this case, if you don't serve an image, the browser will show a placeholder icon that will look ugly and give the impression that your service is broken!

    What I do is, look for the Accept header field. When your script is called via an img tag like this, you will see something like following in the header of the request -

    Accept: image/gif, image/*
    Accept-Encoding:gzip,deflate
    ...
    

    When there is "image/"* string in the Accept header field, I supply the image, otherwise I just reply with 204.

提交回复
热议问题