使用Javascript文件进行随机阻止? [英] Random Blocking with Javascript-File?

查看:70
本文介绍了使用Javascript文件进行随机阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Steve Souders的著作"High Performance Web Sites"中有一个JavaScript阻止示例的例子: http://stevesouders.com/hpws/js-blocking.php

There is an example of javascript blocking from Steve Souders from his Book 'High Performance Web Sites': http://stevesouders.com/hpws/js-blocking.php

JavaScript不再阻止下载,但仍然阻止渲染.

Javascripts don't block Downloads anymore, but still do block rendering.

..但有一个奇怪的下载活动:

.. but there is a strange download activity:

有5个并行下载(在Firefox 3或IE 8中,从同一服务器/主机最多可以下载6个)

There are 5 parallel downloads (max 6 are possible in Firefox 3 or IE 8 from the same server/host)

  • 4张图片(主机1中2张图片,主机2中2张图片)
  • 介于两者之间的1个JavaScript

页面中还有第五张图片,但是第五张图片的加载不是并行进行的,而是在Javascript完成加载后进行的.

there is also a 5th image in the page, but the loading of this fifth image does not occure in parallel, but only after Javascript has finished loading.

那为什么Image不与其他组件并行加载?其他4张图片呢?

so why does that Image not load in parallel with the other components? and the other 4 images do?

如果使用Firebug的网络"面板,您可能会明白我的意思!

If you use the Net panel of Firebug you may see what I mean!

推荐答案

想象一下,光标从上到下在HTML文档中移动. 光标位于每个元素处,它解析元素/图像. 遇到图像时,将开始加载图像,并且光标会继续移动,无需加载图像即可继续渲染.

Imagine a cursor moving through the HTML document from top to bottom. At each element the cursor is at, it resolves the element/image. When an image is encountered, an image load is started and the cursor moves on, the image doesn't need to be loaded for the renderer to continue.

一旦光标击中了脚本标签,它将首先加载该脚本,然后执行该脚本,然后继续执行下一个元素.基本上,它认为脚本标签具有较高的优先级,并且只有在脚本完全解析后才能继续进行;加载,评估和执行.

Once the cursor hits a script tag it first loads that script and then executes it before proceeding to the next element. It basically holds that script tag to be high priority and will only proceed once the script is fully resolved; loading, evaluation and execution.

因此,脚本标记后出现的所有HTML(图像或其他)都将被保留.

So any HTML (image or otherwise) that comes after the script tag is put on hold.

这是JS阻止的含义,当使用纯HTML插入脚本时会发生这种情况.

This is what is meant with JS Blocking and occurs when scripts are inserted using plain HTML.

可以通过使用JavaScript插入脚本来避免这种情况,因为尽管您创建了HTML元素并将它们附加到DOM,但由于这完全是另一个过程,因此它不会中断HTML呈现光标.

This can be avoided by inserting scripts using JavaScript, because though you create HTML elements and append them to the DOM, it does not interrupt the HTML rendering cursor since thats another process entirely.

这篇关于使用Javascript文件进行随机阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆