V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sciel
V2EX  ›  程序员

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

  •  
  •   sciel · 2022-07-07 14:11:09 +08:00 · 726 次点击
    这是一个创建于 664 天前的主题,其中的信息可能已经有所发展或是发生改变。
    sciel
        1
    sciel  
    OP
       2022-07-07 14:22:41 +08:00
    原来是背景图片的原因,加了一个判断就不会发起两次请求了。

    ```
    {{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

    可是这是为什么呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2294 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 15:27 · PVG 23:27 · LAX 08:27 · JFK 11:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.