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

275
Views
How to import javascript from filename variable?

Is it possible to import javascript from a filename stored in a variable to be determined at runtime, something like below?

const mydir="./bobs_pictures.js"
import pictures from mydir;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve that using dynamic imports, which run asynchronously.

const importPromise = import(mydir);
importPromise.then((module) => {
  // do something
});

If you want to use it across a function / module, note that it must be an async function, and then you'll be able to use it in a regular way with await:

async () => {
  const mydir = "./bobs_pictures.js";
  const module = await import(mydir);
}

PS. please check browser compatibility. You might need to use an external tool in order to run this on older browsers.

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!