Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda