aspirinemaga
aspirinemaga

Reputation: 3937

Is it okay for performance to use a lot of ID tags?

As mentioned in title, I want to find out if there is really some performance overhead when using a lot of ID tags in html.

I know the difference between CLASSes and IDs, but I'am not sure about their performance. As far as I know, IDs have specific functionality both for JS and Browser. Browser stores them in it's memory somewhere, and JS uses it to get it from Browser's memory to access them much faster than traversing the whole source code in searching of a specific CLASS.

So, if I don't need to access the ID's with JS or anything else, will be it reasonable to use them in HTML markup?

Upvotes: 1

Views: 848

Answers (2)

Michael Durrant
Michael Durrant

Reputation: 96484

The simple answer is yes but usually not much unless there are many hundreds or thousands.

The detailed answer to this question (as stated) is "it depends".

It depends on:

Your definition of 'a lot'. Some folks would consider 100 a lot, others a 1000, others 10,000

Which browser being used and the version of the browser.

The machine being used, how fast the cpu is, etc.

The OS being used.

The internet (regional/local) speed at that time to download all the div tags.

Where the div's are and if any of the page can load without them.

In conclusion:- given we're talking about web apps and many differences based on user clients, keep the number of div's low if possible.

Upvotes: 1

Daniel Hunter
Daniel Hunter

Reputation: 2866

I have never noticed a degradation of performance as the number of id's are used in HTML tags.

The thing that would degrade performance in my opinion would be the use of client side scripting to manipulate the HTML the ID's are assigned to in mass.

This is my opinion based on experience. No research completed on the subject.

Upvotes: 0

Related Questions