• 请不要在回答技术问题时复制粘贴 AI 生成的内容
apple2026
V2EX  ›  程序员

请教一个问题哈,服务端渲染 html,为什么有些页面只发送一次类型为 document 的请求,有些页面还会另外发起类型为 text/html 的请求?如何让浏览器不发送类型为 text/html 的请求呢?不然数据库会查两边。

  •  
  •   apple2026 · Jul 7, 2022 · 1121 views
    This topic created in 1406 days ago, the information mentioned may be changed or developed.
    apple2026
        1
    apple2026  
    OP
       Jul 7, 2022
    原来是背景图片的原因,加了一个判断就不会发起两次请求了。

    ```
    {{if.node.BgImg}}
    <style>
    #wrapper {
    background-image: url({{.node.BgImg}}), url({{.node.BgImg}});
    background-repeat: repeat-x, repeat;
    /*background-position: center;*/
    /*background-attachment: fixed;*/
    }
    </style>
    {{end}}
    ```
    如果背景图片不存在就会发起类型为 `text/html` 的请求 header 头里面为 Sec-Fetch-Dest: image
    而正常的 类型为`document`的请求,header 头里面为 Sec-Fetch-Dest: document

    可是这是为什么呢?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3249 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:53 · PVG 21:53 · LAX 06:53 · JFK 09:53
    ♥ Do have faith in what you're doing.