jquery - Conditionally executing javascript & performance -


i've inherited project i'm seeing lot of conditional lines in coffeescript files such

$ -> if $('#listing_address').length > 0   #javascript here 

which is, understand, executing following javascript if first finds #listing_address element on page.

does have noticeable performance benefit? standard practice? should giving pages unique id, executing page's javascript on page needed?

as @kevinb said, depend on code there's after. simple $('.x').show()? if yes, doesn't matter.

but instead of using style, i'd rather recommend use modules (like, commonjs modules) , require 1 page. believe you're using rails (because seems js code compilated), can use sprockets gems allow use files modules


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -