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

206
Vistas
WebComponent setter not triggered if defer is used

I recently noticed that a setter in a web component is not being called when you inject the webcomponent javascript file with a script tag where the defer attribute is used. You can see the code here: https://codesandbox.io/s/web-component-with-setter-1ij4o

Within the script tag of the index.html, I set the property foobar to "test". This should trigger the setter of the webcomponent, which should print the value "test" to the screen by an alert command. But this does not happen. If you delete the defer attribute, everything works as expected. Can you tell me why this is happening, and do you have a solution where the setter is being called without deleting the defer attribute?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

What's happening is that your inline script is running before the deferred script.

You can solve this by either putting your inline script in a file and loading it with the defer attribute OR by putting the inline code inside an event listener to run after the 'DOMContentLoaded' event.

document.addEventListener('DOMContentLoaded', () => {
  const wc = document.querySelector("custom-text");
  wc.foobar = "test";
});
about 4 years ago · Juan Pablo Isaza Denunciar
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