Where to place JavaScript in an HTML file?

前端 未结 12 2353
萌比男神i
萌比男神i 2020-11-22 04:30

Say I have a fairly hefty JavaScript file, packed down to roughly 100kb or so. By file I mean it’s an external file that would be linked in via

12条回答
  •  一个人的身影
    2020-11-22 04:53

    I would say that it depends of fact what do you planed to achieve with Javascript code:

    • if you planned to insert external your JS script(s), then the best place is in head of the page
    • if you planed to use pages on smartphones, then bottom of page, just before tag.
    • but, if you planned to make combination HTML and JS (dynamically created and populated HTML table, for example) then you must put it where you need it there.

提交回复
热议问题