Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

380
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda