DEV Community

ATF98
ATF98

Posted on

HTML or JavaScript, what should I write my Markup with?

Let us say that my website have a lot of things shown when i press button, which better:
1- having the Markup in the HTML file and use display {none, block, etc}
2- write the Markup using JavaScript with the function createElement

and why?
Thank you all !

Top comments (6)

Collapse
 
rhymes profile image
rhymes

HTML.

It's also going to be faster because the client already has the content in the page, you just need to flip the visibility with JS. You can also rely on the HTTP cache.

Unless we're talking about thousands or millions of rows in a table for example, that's probably something you want to have JS handle for you on demand.

Collapse
 
atf98 profile image
ATF98

Yeah this is what i thought about HTML it would be faster, but what make me ask this question is maybe in the future when the website start to be wide, it will be more easy to change the element by the unauthorized developer, which it's something I don't know if it good or not. Sometimes you don't want the element render only if he do what you want do, not after, not before, in that case you're forced to use the DOM
Hope I explain my point !

Collapse
 
rhymes profile image
rhymes

Sorry, I'm not sure I understood. Are you worried about security? The website runs on the user's computer and as long as you do the usual things server side to mitigate possible security flaws and don't store any sensible information on the local storage you shouldn't have any problems.

What sort of website will you build?

Thread Thread
 
atf98 profile image
ATF98

Yeah,I'm worried about the security, but yeah I know everything is done locally, so that mean I'm not worried about the data and these thing, what I'm worried about exactly is the people whom always trying to find a bug in your website, and sometimes there is a way of taken benefits of the Markup, if you didn't manage it well!

Social media website, what I'm talking about

Collapse
 
maniflames profile image
Maniflames

I'd go for option one. It's less work and in my opinion more readable for future you.

Collapse
 
atf98 profile image
ATF98

Good point, maybe as you said the HTML saved the patterns of your design for the future