Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!