Table of Contents
setTimeout (slow, takes about 10 sec)
img.onerror (data:uri)
script.onreadystatechange
script.onload (data:uri)
xhr.onreadystatechange (data:text/plain,foo)
self.postMessage
Home Web Front-end JS Tutorial javascript asynchronous programming_javascript skills

javascript asynchronous programming_javascript skills

May 16, 2016 pm 06:25 PM
Asynchronous programming

就好像排队,前面的人忙着忙着突然上厕所了,后面的人阻塞在这里,因此我们就需要让前面的人死到一边去,让后面的人跟进……AJAX就是这个概念,请求还在继续,但我们还可以做其他事。

javascript中实现这个功能的是来自BOM的一个函数setTimeout,但相关的DOM操作也提供了一系列实现。如XMLHttpRequest对象与script标签的onreadystatechange回调,image的onload与onerror回调,iframe的onload,DOM元素的事件回调,HTML5的跨域消息传送postMessage,QuickTime与flash对象的加载……

setTimeout的零秒延迟在前些年时间被国内宣扬得特别厉害,但setTimeout是所有延迟中最慢的,最少要花上10多毫秒,如果用setTimeout来开发特效,这特效会运行得比较慢。下面是一个性能测试:


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement asynchronous programming with C++ functions? How to implement asynchronous programming with C++ functions? Apr 27, 2024 pm 09:09 PM

How to implement asynchronous programming with C++ functions?

Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks Nov 18, 2023 am 10:06 AM

Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks

How to use ReactPHP for asynchronous programming in PHP How to use ReactPHP for asynchronous programming in PHP Jun 27, 2023 am 09:14 AM

How to use ReactPHP for asynchronous programming in PHP

How to implement asynchronous message handling in PHP How to implement asynchronous message handling in PHP Jul 10, 2023 am 08:19 AM

How to implement asynchronous message handling in PHP

In-depth understanding of the new features of PHP8: How to use asynchronous programming and code efficiently? In-depth understanding of the new features of PHP8: How to use asynchronous programming and code efficiently? Sep 11, 2023 pm 01:52 PM

In-depth understanding of the new features of PHP8: How to use asynchronous programming and code efficiently?

How does the golang framework handle concurrency and asynchronous programming? How does the golang framework handle concurrency and asynchronous programming? Jun 02, 2024 pm 07:49 PM

How does the golang framework handle concurrency and asynchronous programming?

Common problems and solutions in asynchronous programming in Java framework Common problems and solutions in asynchronous programming in Java framework Jun 04, 2024 pm 05:09 PM

Common problems and solutions in asynchronous programming in Java framework

What are the advantages and disadvantages of asynchronous programming in PHP? What are the advantages and disadvantages of asynchronous programming in PHP? May 06, 2024 pm 10:00 PM

What are the advantages and disadvantages of asynchronous programming in PHP?

See all articles