简体   繁体   English

使用Javascript文件进行随机阻止?

[英]Random Blocking with Javascript-File?

There is an example of javascript blocking from Steve Souders from his Book 'High Performance Web Sites': http://stevesouders.com/hpws/js-blocking.php 史蒂夫·索德斯(Steve Souders)在其“高性能网站”一书中有一个JavaScript阻止示例: http : //stevesouders.com/hpws/js-blocking.php

Javascripts don't block Downloads anymore, but still do block rendering. Javascript不再阻止下载,但仍然阻止渲染。

.. but there is a strange download activity: ..但有一个奇怪的下载活动:

There are 5 parallel downloads (max 6 are possible in Firefox 3 or IE 8 from the same server/host) 并行下载5次(从同一服务器/主机的Firefox 3或IE 8中最多可以下载6次)

  • 4 Images (2 from host1, 2 from host2) 4张图片(主机1提供2张图片,主机2提供2张图片)
  • 1 Javascript in between 中间有1个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. 页面中还有第5张图片,但是该第5张图片的加载不是并行进行的,而是仅在Javascript完成加载后进行。

so why does that Image not load in parallel with the other components? 那么为什么该Image不能与其他组件并行加载? and the other 4 images do? 而其他4张图片呢?

If you use the Net panel of Firebug you may see what I mean! 如果使用Firebug的“网络”面板,您可能会明白我的意思!

Imagine a cursor moving through the HTML document from top to bottom. 想象一下,光标从上到下在HTML文档中移动。 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. 加载,评估和执行。

So any HTML (image or otherwise) that comes after the script tag is put on hold. 因此,脚本标记后的所有HTML(图像或其他图像)都将被保留。

This is what is meant with JS Blocking and occurs when scripts are inserted using plain HTML. 这就是JS阻止的含义,当使用纯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插入脚本来避免这种情况,因为尽管您创建了HTML元素并将它们附加到DOM,但它不会中断HTML呈现光标,因为那完全是另一个过程。

not an answer, just a screenshot to illustrate the question: why is the download of the last image only started after the javascript has stopped downloading? 不是答案,而是一个截图来说明问题:为什么最后一张图片的下载仅在javascript停止下载后才开始?

萤火虫的屏幕截图

and here a possible answer: i put the html of the example on my server (all images and javascripts still on souders's server) and then looked at firebug: now i see the traditional blocking behavior: 这是一个可能的答案:我将示例的html 放在服务器上 (所有图像和javascript仍在souders的服务器上),然后看了萤火虫:现在我看到了传统的阻止行为:

在此处输入图片说明

loading the first javascript (util.js) blocks the loading of all the following images, loading the second javascript (the slow on) blocks the loading of all images after that. 加载第一个javascript(util.js)会阻止所有后续图像的加载,加载第二个javascript(slow on)会阻止之后所有图像的加载。

maybe having the html and the scripts on the same server is some kind of special case that is treated differently by the browsers. 也许将html和脚本放在同一台服务器上是一种特殊情况,但浏览器会对此加以区别对待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在d3中单击按钮执行Javascript文件 - Execute Javascript-File with Button click in d3 包含另一个文件时,JavaScript文件停止工作 - JavaScript-file stopped working when including another file 通过使用其他文件来填充Javascript文件的数组 - Fill up array of a Javascript-File by using other file 从.tpl链接到外部Javascript文件不起作用 - Linking to external Javascript-file from .tpl does not work 在视图中强制重载Javascript文件而不发布服务器代码 - Force reload Javascript-file on publish WITHOUT server code in view 将包含外部 javascript 文件的外部 html 文件加载到 div - Loading an external html-file which includes an external javascript-file to a div 如何在引用的JavaScript文件中而不是之间使用Thymeleaf <script> tags - How to use Thymeleaf in a referenced JavaScript-File instead of between <script> tags 当文件夹的内容发生变化时,如何重新运行 Javascript 文件? - How do I re-run a Javascript-file when the content of a folder changes? 如何在 TYPO3 中的 JavaScript 文件中使用 Fluid (ViewHelper) 显示图片 - How to display a picture using Fluid (ViewHelper) from a JavaScript-file in TYPO3 如何调用包含在 PHP 文件或 Javascript 文件中的“函数构造”? - How do I call a 'conscruct of functions' that are included in a PHP-file or a Javascript-file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM