Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Observed difference in file size between Nginx and Express server when serving static bundles

I am trying to optimize serving my static bundles generated from my React Webpack app. In this process, I noticed that for same files, when serving the content through an Express server, the file sizes were comparatively lower than when served through nginx.

Here is my express code to serve the bundle:

app.use(express.static(project.paths.dist()));

Here is my nginx config:

server {
listen 80;

root /home/test/dist/;
index index.html index.htm app.js;

server_name www.ranodom.com;

location / {
    try_files $uri /index.html;
}

error_log /var/log/nginx/test/website-error_log error;
access_log /var/log/nginx/test/website-access_log;
}

When served through express:

Express served files

When served through nginx: Nginx served files

As visible from above screenshots, the file sizes differ drastically. The actual file sizes as present in the folder is equal to the one being served from Nginx server.

My question is, what can be the reason for this difference? Does express static optimizes/compresses the served files or is there a catch? If there is so much difference, would it be better to serve these files via express server and routing to index page via nginx?

PS. The above files are already uglified and minified using webpack.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Just realized that the compression middleware was enabled in my express server and hence the reduction in size.

If anyone else stumbles on this post, do notice that you can obtain similar results using nginx by using the below mentioned configs.

gzip on;
gzip_min_length 1000;
gzip_types text/html text/css application/javascript text/javascript text/plain text/xml application/json;
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda