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

383
Visualizações
Javascript Import from Relative URL (Browser)

Is there a way to import a Javascript file from a URL (relative) in the browser from Javascript code?

I know you can import a Javascript file from HTML but I don't want to do that.

I would expect something like this:

import { functionName } from "/static/javascript/fileName";

functionName();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, relative URLs are absolutely fine. A couple of things to note:

  • Like all other relative URLs in the browser environment, they're resolved client-side.
  • Your import is syntactically correct, but you probably meant to have .js on there, because browsers do not add file extensions for you.

If your import were in a file at https://example.com/something/somefile.js, your import would be telling the browser to import from https://example.com/static/javascript/fileName.

Guessing a bit from the name of your path, you probably wanted:

import { functionName } from "./fileName.js";

That tells the browser to import from fileName.js on the same path as the JavaScript file the import occurs in. So if the import were in https://example.com/something/somefile.js, the browser would look for https://example.com/something/fileName.js.

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