我刚刚在我拥有的临时网站上收到了以下反馈。
There are over 100 lines of JavaScript code [in the footer] which should be in a separate file for performance, not in the markup.
尽管我的印象是,在页脚中提供它可以提高性能,因为它减少了一个 http 请求。
对于生产环境,哪种方法更好(内联或外部)?
最佳答案
将 JS 保存在外部文件中可以在页面之间缓存和重用(或重新加载同一页面)。
首次加载时会有一个小的性能损失,以换取 future (相对)较大的增强。
关于JavaScript 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649720/