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

459
Visualizações
Problem linking a JS file to a HTML file using Eleventy/11ty? Currently getting 'GET net::ERR_ABORTED 404 (Not Found)'

I'm creating a site using an SSG (11ty) and I'm having issues adding an external js file to my html. I've tried placing my tag in a few different places within my html, but I receive the below error every time I check the console log:

'GET net::ERR_ABORTED 404 (Not Found)'

In a regular html file I would link to my js file by putting the script tag at the bottom of the body. However as I'm using 11ty to template my pages, the bottom of the body is actually in a separate nunjucks (.njk) file.

I've tried putting the tag at the bottom of the html file, but when my code is served with 11ty the tag appears above the footer inherited from the layout.njk file. I've also tried writing the script tag at the bottom of the body in the .njk file, but in every instance I get the same error.

Does anyone know why I am receiving this error message and where the correct place is to include my tag?

Here is my file structure:

src
|-- _includes
|  |-- layout.njk
|-- carousel.js
|-- gallery.html    

This is the bottom of the body of my layout.njk template file:

        <script src="carousel.js"></script> 
    </body>     
</html> 

This is the front matter from my gallery.html file:

---
layout: layout.njk
title: The Gallery
---

This is the bottom of my gallery.html file:

        </div>

    </div>    

<script src="carousel.js"></script>

This is my .eleventy.js config file:

module.exports = function (eleventyConfig) {
    eleventyConfig.addPassthroughCopy("./src/js");
    eleventyConfig.addPassthroughCopy("src/img");
    eleventyConfig.addPassthroughCopy("src/css");
    return {
        dir: {
            input: "src",
            layouts: "_includes",
        },
    };
};   

Thanks!

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

0

I believe that the problem isn't with your HTML <script> tag, but with Eleventy not copying the js file into your _site directory.

In your .eleventy.js config, you're copying src/js into your output folder, but your carousel.js file is not in a js folder. You can fix this by adding

eleventyConfig.addPassthroughCopy("src/carousel.js")

to your config, or by placing your carousel file in src/js, and updating your script tag to

<script src="/js/carousel.js"></script>

Either of these solutions should work.

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