了解渲染阻止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.css
和style.css
包含一些立即影响上面的折叠内容或HTML中的元素的规则。 但是,autocomplete.css
仅包含稍后由某些JavaScript使用的类。现在,我们进一步假设浏览器已经下载了
reset.css
和style.css
但autocomplete.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
andstyle.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
andstyle.css
butautocomplete.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 missingautocomplete.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 thescript.js
javascript blocked until theautocomplete.css
is there?Note, I am referring to two different things: rendering and script execution.
原文:https://stackoverflow.com/questions/42581143
最满意答案
从精美的手册 :
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"}
. Thecallback
may be either the name of a method on the view, or a direct function body. Omitting theselector
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')
相关问答
更多-
骨干事件没有解雇(Backbone event not firing)[2023-06-20]
你要覆盖你的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}); $ ...
-
主干点击事件未触发(backbone click events not firing)[2024-01-25]
我同意安德鲁 - 事件将被绑定到你的视图元素(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 -
骨干点击事件没有发射(Backbone click event not firing)[2023-05-28]
从精美的手册 : 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 event not firing! (backbone.js))[2022-12-05]
代替: '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 = ...
-
Keypress事件只发射一次(Keypress event firing only once)[2023-09-05]
活动活页夹应始终可用; 如果它不是因为您正在更改HTML结构(添加或删除节点)。 在您的情况下,您在运行时动态更改HTML,您需要使用.on() 试试这个而不是.bind() : $('#id').on({ keypress: function () { alert("hi"); } }); $('.ClassName').on({ keypress: function () { alert("hi"); } }); // IF YOU ...