G
G
gifon2022-02-28 18:46:54
Node.js
gifon, 2022-02-28 18:46:54

How to serve a static brotli site?

Hello, I have a spa site compressed to brotli,
how can I serve it.
For example

app.use(express.static(path.join(__dirname, "../", "prerendered")));
app.use(function (req, res) {
  res.sendFile(path.join(__dirname, "../", "prerendered", "index.html"));
});

works.
But when I serve brotli as
app.use(express.static(path.join(__dirname, "../", "prerendered")));

app.use(function (req, res) {
  res.sendFile(path.join(__dirname, "../", "prerendered", "index.html.br"));
  res.set("Content-Encoding", "brotli");
});

nothing works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Goretsky, 2022-02-28
@gifon

Try this

app.use(function (req, res) {
          res.writeHead(200, {
            'Content-Encoding': 'brotli';
          })
  res.sendFile(path.join(__dirname, "../", "prerendered", "index.html.br"));
});

The header must not follow the data!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question