Search code examples
javascriptjqueryunobtrusive-javascript

is unobstrusive javascript style slower than the usual?


At the moment I'm doing jquery like this

<input id='aa' ... >
<script>
makeIt('aa', 2,'home/getitems',10)
</script>

I can also do it like this

<input class='theOne' ae-minLen='3' ae-url='home/getitems' ae-maxRes='10' ... >

and the makeIt is called on document.ready for $(document).find('.theOne').each ...

and it gets the values using

$(this).attr('ae-minLen') etc.

but, I'm wondering whether the unobtrusive way is slower than the usual ?

EDIT: ppl say it's slower, how much slower is it, should I have a 5MB html to actually notice it ?


Solution

  • Yes the unobtrusive way is the slowest, and will always be.

    The question is weather or not this is relevant.

    If you way the pros and cons, you will see that in most cases, the unobtrusive way will give you a lot of benefits (for instance easier maintainability of your code) for a very little performance cost.

    Read up on when to optimize