大网数据广告活动
网站运营与故障问答

Loading order of assets stack: how is it managed by browser?

· 52CE 我爱测

I have an issue, which i can't explain me - i seem to miss some basics. Could somebody explain me in plain words the browser behavior, which i describe further? Given is a html document with some javascripts implemented on the bo…

问题原文

原帖链接 · Evgeniy · CC BY-SA 3.0

I have an issue, which i can't explain me - i seem to miss some basics. Could somebody explain me in plain words the browser behavior, which i describe further?

Given is a html document with some javascripts implemented on the bottom, according to performance best practices (but not async and/or defer). All fine, browser reads html file from top to bottom without to be blocked, reads all resources and forms the loading stack (all assets, images, javascripts, fonts, ...).

Then i realize in the timeline of dev. tools: the stack is ordered in that order, as assets are appearing in the html file:

  • firstly some images from CSS file, which is in the head,
  • then some images from the middle of the body,
  • then javascripts on very bottom, like they are implemented in the html file, and as i expect to see them.

But in the network diagram, if i sort it on download start time, i realize, that javascripts are loaded at the very first, before everything.

This is, what i don't understand and where i need an explanation: why the network diagram shows me a loading order, which differs from the implementing and timeline order?

On attached images is the loading order in timeline and waterfall visible:

已采纳解答

原帖链接 · norcal johnny · CC BY-SA 3.0

This has been answered on stackoverflow.

If you aren't dynamically loading scripts or marking them as defer or async, then scripts are loaded in the order encountered in the page. It doesn't matter whether it's an external script or an inline script - they are executed in the order they are encountered in the page. Inline scripts that come after external scripts have are held until all external scripts that came before them have loaded and run.

Full answer can be found here. https://stackoverflow.com/questions/8996852/load-and-execute-order-of-scripts/8996894#8996894

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。