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

129
Views
Load Javascript conditionally with Parcel not working

I've been trying to load a javascript file conditionally but it doesnt work when i build the app with parcel. I don't know what's happening but it seems like parcel does not build the file when i load it. The function i want to achieve is one that a certain javascript file only loads on Desktop devices/devices with width >= 600px. Tried building with Vs Code Live Serve, and it seemed to work just fine, however when i build with parcel, this function does not work. Any help please?

    <script>
    var matchMedia = window.matchMedia("(max-width:600px)");

        if (matchMedia.matches) {
          return;
        } else {
            
            var script = document.createElement('script');
            script.type = "text/javascript";
            script.src = "assets/js/main.js";
            document.body.appendChild(script);    
        }
</script>
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!