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

131
Vistas
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
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