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

236
Vistas
When dynamically creating HTML elements with Javascript is it better to have the CSS predefined in a file, or dynamically assigned?

Is it better from performance standpoint / a more efficient use of memory to have the CSS be created with the dynamically generated HTML elements, or to have the classes predefined in a CSS file waiting to be used?

I could imagine that having CSS sitting waiting to be used could make the CSS file unnecessarily big, whereas using JS to create the CSS could be a less efficient use of memory and processing power.

Would love to hear others' thoughts on it.

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

0

I vote for using css classes in separate file :

  1. To separate the display from the processing or the traitement
  2. To be able to manage any changes in the future
  3. Having the possibility to make your CSS dynamic with CSS Custom Properties
  4. Possibility to use css Modules
  5. Take all css advantage
about 4 years ago · Juan Pablo Isaza Denunciar

0

Personally, I prefer having things separate, since it's easier to find/read/update later one. Having a bunch of CSS styles mixed in with JS could make it hard to read and maintain in the long run.

I also wouldn't worry about optimization until you feel that your code is taking a while to load.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Defined in a css file, is a good practice. If you need to update the css after generating html, Then it will be a good to define in css classes.

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