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
Post a Comment