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

234
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!