内联javascript是否会阻止UI线程? [英] Does inline javascript block the UI thread?

查看:130
本文介绍了内联javascript是否会阻止UI线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在外部脚本如何阻止UI线程但我不清楚阻止是否实际上是由于存在< script> 标记或 src ='/ myscript.js' src属性。

I read this nice article on how external scripts block the UI thread but it wasn't clear to me whether the blocking is actually due to the presence of the <script> tag or the src='/myscript.js' src attribute.

我的问题是内联javascript(缺少src)属性声明),例如:

My question is does inline javascript (lacking a src attribute declaration), for example this:

<script type='text/javascript'> alert('am i blocking too?');</script>

或者这个:

<script type='text/javascript'> var php='<?=json_encode($myObj)?>';</script>

还会阻止UI线程吗?

推荐答案

任何加载JS文件或执行任何任何 JS(无论是在外部文件还是内联中)都将阻止UI线程。

Any loading of a JS file or any execution of any JS (whether in an external file or inline) will block the UI thread.

< script> 标记的例外是异步加载,脚本将在后台异步加载和执行。

The exception for the <script> tag is an asynchronous load where the script will load and execute asynchronously in the background.

还有延迟加载(即 defer 属性),它告诉浏览器不要实际执行JS,直到页面的其余部分已加载。

There are also "deferred" loads (i.e. the defer attribute) which tells the browser not to actually execute the JS therein until the rest of the page has loaded.

这篇关于内联javascript是否会阻止UI线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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