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

135
Visualizações
Fetch returns 404 not found in web component

I have a component, facts-and-steps.js, and I want to import an HTML file that contains a <template> in it. I am trying to use fetch to get the template.html file, but it's returning a 404 error.

Here is the code that returns 404:

let x = await (await fetch('./template.html')).text();
//x prints "Not Found"

I am using the Open-wc @web/dev-server - https://modern-web.dev/docs/dev-server/overview/

How can I fetch files?

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

0

fetch loads relative resources based on where it is executed, not where it is loaded from. Say you have example.com/components/facts-and-steps/facts-and-steps.js loaded and executed on example.com/. It will try to load example.com/template.html. You basically have a couple of options.

  1. Load with a more complete path
fetch('/components/facts-and-steps/template.html')
  1. Use a import.meta. Web.dev has a good guide.
fetch(new URL('./template.html', import.meta.url))
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