开发者

What gives better performance, attributes via html or jquery?

so sometimes my html needs some special classes/div's/attributes/.. for the jquery scripts to work (the "no-javaSript" version of the site doesn't need these elements to work properly). I'm sure you know what I am talking about.

Now I was wondering what is better for the perf开发者_JAVA技巧ormance/load time of the site. Having the "extra" html code already written in the html or adding them by the script?

If you have any experience about this, I would be glad if you share it with me.

Thank you very much!


You won't feel any substantial difference in using either of these approaches, but it's much less overhead adding the custom attributes serverside, at the time you're generating them.

If you're doing that clientside - you'll have to attach events to the page load, traverse the DOM looking for the required tag names, manipulate the attributes of these elements, causing modifications to the DOM and possibly triggering reflow, which you don't need at all.

Whilst when you do it serverside - no additional calculations are required, you simply increasy the output weight by several bytes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜