What's the name of Google Analytics async design pattern and where is it used?

前端 未结 4 1116
[愿得一人]
[愿得一人] 2020-12-12 10:38

Google Analytics async code uses a very distinct design pattern for javascript code execution.

The code depends on a library and it doesn\'t know if the library has

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 11:24

    In 2014 Ilya Grigorik wrote a post titled Script-injected "async scripts" considered harmful. That post links to this question and uses the phrase "asynchronous function queuing" as the name of the design pattern used by Google Analytics.

    Async function queuing differs from more recent design patterns like Fetch Injection, which don't require or need a globally defined queue. Here's an example of Fetch Injection implemented in the Fetch Inject module and used to asynchronously download resources in a document:

    Notice the Fetch Injection design pattern is capable of loading CSS in addition to JavaScript in parallel, eliminating the blocking behavior of CSSOM and the Web Font download, greatly reducing perceived latency. Script execution order is fully preserved using an easy-to-understand API, making it simple to manage loading complex groups of resources with total programmatic control.

提交回复
热议问题