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

231
Views
How to load external script file in index.html differently on build mode? (Vue.js)

I am trying to load external script file only on a production mode.
At first, I tried to use NODE_ENV, but found it impossible.
So I compared URL using window.location.host as shown below.

Isn't there a more sophisticated way?

<!DOCTYPE html>
<html>
<head>
...
<script>
  window.addEventListner('load', function(event) {
  let host = window.location.host;
  if (host.match('some production URL')) {
    var script = document.createElement('script');
    script.setAttribute('src', '~.js');
    document.head.appendChild(script);
  }
</script>
</head>
<body>
  </div id="app></div>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
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!