【发布时间】:2021-11-03 02:59:07
【问题描述】:
当我从浏览器打开 html 文件时,它会使用以下内容:
但是当我从 Express 服务器发送相同的文件时,内存消耗明显更高:
确实,这不是一个巨大的内存消耗,但它是一个非常明显的区别,为什么会发生这种情况?,是 Express 向客户端发送我不知道的东西(标题,cookie,什么?)?
在服务器上,我只有一个 JavaScript 文件,其中包含一个使用 Express 的 sendFile 函数发送 html 文件的路由:
const express = require('express');
const { join } = require('path');
const server = express();
server.get('/', (_, res) => {
res.sendFile(join(__dirname, 'render.html'));
});
server.listen(3000, () => {
console.log('Server is running in port 3000');
});
而您发送给客户端的 HTML 文件仅包含以下内容:
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<header>
<h1>This is Header</h1>
</header>
<main>
<section>
<h1>Section 1</h1>
</section>
<section>
<h1>Section 2</h1>
</section>
</main>
<footer>
<h2>This is Footer</h2>
</footer>
</body>
</html>
没有别的了。
我在 Google Chrome 和 Edge 上试过,希望你能帮助我理解 c:
【问题讨论】:
标签: node.js express server client sendfile