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

323
Visualizações
Synchronous download text file JavaScript

I'm making a really light weight web page that downloads a file and then displays content based on the file. There is no displayed content without the file, and I have no plans to scale up this webpage. I do not want to use async methods unless I absolutely have to.

How do you download a file in such a way that JavaScript will pause until the file is downloaded.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just wrap your entire script in an async IIFE and await the single network request:

// immediately invoked async function expression:
(async () => {
  // all of your sync code before the fetch request to get the file

  const response = await fetch(url);
  // handle response, parse data, etc.

  // all of the rest of your sync code after the fetch request,
  // which won't execute until after the fetch promise is
  // resolved as the response (or rejected)
})();
about 4 years ago · Juan Pablo Isaza 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