Is it practically good to put JS files at the bottom of webpage?

前端 未结 7 1426
情歌与酒
情歌与酒 2020-12-18 03:26

It is widely recommended that JS files should be put at the bottom of page to allow html codes to be loaded first. In this case, visitors will see something when waiting for

相关标签:
7条回答
  • 2020-12-18 03:50

    I'm not really that familiar with putting the scripts in the footer, but you may want to look into the various ways of telling the page to only run the JavaScript AFTER the page is fully loaded.

    This opens up a couple options - you could have JS dynamically load external scripts only after the page is ready.

    You can also hide some or all of the page content, and then just make it visible after the page is ready. Just make sure you hide it with JS, so that non-js browsers can still see it.

    See these:

    • https://www.google.com/search?q=javascript+page+ready
    • http://api.jquery.com/ready/
    0 讨论(0)
提交回复
热议问题