首页 \ 问答 \ 了解渲染阻止CSS(Understanding Render Blocking CSS)

了解渲染阻止CSS(Understanding Render Blocking CSS)

我试图了解如何在特定设置中评估CSS:

假设我的<head>标记中包含以下内容:

<html><head>
...
    <link href="reset.css" type="text/css" rel="stylesheet">
    <link href="style.css" type="text/css" rel="stylesheet">
    <link href="autocomplete.css" type="text/css" rel="stylesheet">
</head>
<body>
... html ...
<script type="text/javascript" src="/js/script.js"></script>
</body></html>

现在,让我们假设reset.cssstyle.css包含一些立即影响上面的折叠内容或HTML中的元素的规则。 但是, autocomplete.css仅包含稍后由某些JavaScript使用的类。

现在,我们进一步假设浏览器已经下载了reset.cssstyle.cssautocomplete.css仍处于未决状态。 我想知道如果浏览器会遇到页面末尾的阻止脚本标记会发生什么? 显然,它可以将HTML呈现给脚本标记,但是缺少的autocomplete.css阻止了脚本的执行?

请注意,脚本标记不是同步。

我读过: https//developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp

并且它说,在CSSOM存在之前,JavaScript的执行被阻止。

现在:1。页面是否会开始渲染甚至autocomplete.css还没有到达? 和2.在autocomplete.css存在之前, script.js javascript的执行是否被阻止?

注意,我指的是两个不同的东西:渲染和脚本执行。


I am trying to understand how CSS is evaluated in a specific setting:

Lets assume I have the following content in my <head> tag:

<html><head>
...
    <link href="reset.css" type="text/css" rel="stylesheet">
    <link href="style.css" type="text/css" rel="stylesheet">
    <link href="autocomplete.css" type="text/css" rel="stylesheet">
</head>
<body>
... html ...
<script type="text/javascript" src="/js/script.js"></script>
</body></html>

Now, let's assume reset.css and style.css contain some rules that immediately affect the above the fold content or the the elements in the HTML. However, autocomplete.css only contains class used that are used later by some JavaScript.

Now, let's further assume the browser already downloaded reset.css and style.css but autocomplete.css is still pending. I am wondering what would happen if the browser would do it encounters the blocking script tag at the end of the page? Obviously, it can render the HTML up to the script tag, but is the execution of the script blocked by the missing autocomplete.css?

Note that the script tag is not a sync.

I've read: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp

And there it says that the execution of the JavaScript is blocked until the CSSOM is there.

Now: 1. Will the page start rendering even autocomplete.css has not yet arrived? and, 2. Is the execution of the script.js javascript blocked until the autocomplete.css is there?

Note, I am referring to two different things: rendering and script execution.


原文:https://stackoverflow.com/questions/42581143
更新时间:2022-02-21 08:02

最满意答案

精美的手册

delegateEvents delegateEvents([events])

[...]事件以{"event selector": "callback"}格式编写。 callback可以是视图上方法的名称,也可以是直接函数体。 省略selector this.el事件绑定到视图的根元素( this.el )。

所以你希望你的events看起来像这样:

events:
    'click': -> console.log('clicked')

演示: http : //jsfiddle.net/6W6QE/


From the fine manual:

delegateEvents delegateEvents([events])

[...] Events are written in the format {"event selector": "callback"}. The callback may be either the name of a method on the view, or a direct function body. Omitting the selector causes the event to be bound to the view's root element (this.el).

So you want your events to look like this:

events:
    'click': -> console.log('clicked')

Demo: http://jsfiddle.net/6W6QE/

相关问答

更多
  • 你要覆盖你的this.el ,你想要做的是 render: function () { var tpl = _.template($('#tpl-sTableList_' + key + 'Row').html()); this.$el.empty().html(tpl); // or if you prefer the old way // $(this.el).empty().html(tpl); return this; }, 如果这导致你的DOM表示有问题, ...
  • 有些事情可能是问题的原因。 首先,你的el声明似乎是可疑的。 如果你想要一个带有这个类的div,你只需要定义className属性,因为骨干视图的默认值是div 。 而不是: el: '
    ' 只需使用: className: 'vendor-video' 我没有看到有关视图初始化方法的任何细节,但最佳做法是初始化视图,然后将其呈现给容器: var yourVideoDivView = new videoDivView({model: model}); $ ...
  • 我同意安德鲁 - 事件将被绑定到你的视图元素(el),所以按钮必须在你的el里面才能被触发 I agree with Andrew - the event will get bound to your view's element (el), so the button has to be inside your el for it to be triggered
  • 从精美的手册 : delegateEvents delegateEvents([events]) [...]事件以{"event selector": "callback"}格式编写。 callback可以是视图上方法的名称,也可以是直接函数体。 省略selector this.el事件绑定到视图的根元素( this.el )。 所以你希望你的events看起来像这样: events: 'click': -> console.log('clicked') 演示: http : //jsfiddle ...
  • 我想要做的是不可能的,原因与Backbone完全无关! 问题是在大多数浏览器中,鼠标/键盘事件不会触发options 。 来自MDN: 从历史上看,Firefox允许键盘和鼠标事件从元素冒泡到父元素。 但是,这不会发生在Chrome中,尽管此行为在许多浏览器中都不一致。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option 导致我进入MDN的SO答案: onclick选项标签不适用于IE和Chrome What I'm trying ...
  • 当您在Backbone视图上指定events哈希时,Backbone使用jQuery .delegate方法来绑定回调,并将View的el作为根元素。 但是,在您的GalleryItemView.render方法中,您实际上并未渲染到视图的el; 你选择了一个完全不同的元素。 因此,事件实际上是在事件哈希作用范围之外触发的。 相反,你需要做这样的事情 window.views.GalleryItemView = Backbone.View.extend({ ... render:function ...
  • 你并不疯狂。 谷歌浏览器最近的更新打破了许多网站的浏览器功能,其中包括NodeCellar教程。 不过,这很容易解决。 Chrome现在要求您阻止dragover事件的默认操作: $('div').on('drop',function(e){ e.originalEvent.stopPropagation(); e.originalEvent.preventDefault(); $(this).html('A file was dropped!'); }).on('dragover' ...
  • 代替: 'click #modal': 'closeModal' 尝试: "click": 'closeModal' Backbone事件使用jQuery的delegate函数,它将处理程序(在本例中为closeModal )应用于匹配给定选择器的所有子closeModal (在本例中click #modal )。 由于click #modal我们在#modal中查找名为#modal的子项,因此未找到任何元素。 看看delegate()看看我的意思。 instead of: 'click #modal' ...
  • 你可以通过删除el参数来解决这个问题: var tv = new TimelineView({ model: t, //el: '#timelineView', }); $("#addProperty").click(function(){ console.log('added') var p = new Timeline({ "name":"Pow", "CSSProperty":"awesome!" }) var ts = ...
  • 活动活页夹应始终可用; 如果它不是因为您正在更改HTML结构(添加或删除节点)。 在您的情况下,您在运行时动态更改HTML,您需要使用.on() 试试这个而不是.bind() : $('#id').on({ keypress: function () { alert("hi"); } }); $('.ClassName').on({ keypress: function () { alert("hi"); } }); // IF YOU ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)