How does the location of a script tag in a page affect a JavaScript function that is defined in it?

后端 未结 9 1276
死守一世寂寞
死守一世寂寞 2020-11-29 04:27

I read that you should define your JavaScript functions in the tag, but how does the location of the

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 04:57

    One of the aspects of placement is performance. See this fine article within the YSlow discussion for why it's sometimes recommended you put them at the bottom of the document.

    As for issues of scope, the usual visibility rules for Javascript (vars defined inside or outside of functions, local, global, closures, etc.) are not affected so far as I know.

提交回复
热议问题