我正在尝试寻找有关如何提高 Web 应用程序前端性能的答案。我的问题是我引用了多个 css/js 文件。 现在浏览器会对每个 css/js 文件进行 http 调用。但我的问题是;
- 它是并行发生还是一个接一个发生? CSS/JS 是否相同?
- 行为(并行或一个接一个)是特定于浏览器的吗?
- 使用脚本标签的异步属性是异步下载的标准方式还是可接受方式?
- 对单个页面的 http 调用次数是否有任何限制?它是特定于浏览器的吗?
- 使用 RequireJS 等 AMD 框架是否可以解决任何性能问题,或者它是否仅用于单页应用开发?
除了提到任何其他通用前端性能改进技巧之外,是否会很棒?
最佳答案
- Does it happen in parallel or happen one after the other ? Is it same for both CSS/JS ?
- Is the behaviour (parallel or one after the other) browser-specific ?
浏览器使用多个连接并行下载网站内容。这些连接的数量取决于浏览器及其用户设置。如果没记错的话,平均连接数是4。
- Is the use of async attribute for script tag standard or accepted way for asynchronous download?
async属性用来表示脚本是异步执行的,不影响下载的优先级
- Are there any limitations to the number of http calls that can be made for a single page ? Is it browser specific?
没有限制,虽然显然您拥有的越多,由于连接限制,页面下载所需的时间就越长。
- Does using AMD frameworks like RequireJS solve any of the performance issues OR is it to be used only in a single-page app development ?
这些框架可以用在任何具有任何结构的网站上。他们的好处来自延迟 JS 的下载,直到页面实际需要它。这意味着可以首先下载其他 UI 元素,例如图像和视频,从而使最终用户的页面加载速度更快。
关于javascript - 前端性能和css/js文件数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27185473/