In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "what is the use of Fetch", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of Fetch" this article?
The concept of Fetch
Fetch provides a general definition of Request and Response (and other objects related to network requests). So that it can be used in more application scenarios in the future: whether it's service worker, Cache API, or other ways to handle requests and responses, or even any way you need to generate your own responses in the program.
It also provides a new definition for concepts related to connectedness, such as CORS and HTTP native header information, replacing their original separate definitions.
You need to use the WindowOrWorkerGlobalScope.fetch () method to send a request or get a resource. It is implemented in many interfaces, more specifically, on the Window and WorkerGlobalScope interfaces. Therefore, resources can be obtained in this way in almost all environments.
Compatibility
The easiest way to see whether a new API will become popular is to look at its compatibility. After all, if the compatibility is not good, it will be difficult for the most useful API to catch on.
The Fetch method is not very compatible for browsers other than IE, which can be said to have a prerequisite for a big hit.
The difference between and AJAX
Since it is used to replace AJAX, there must be some feature advantages that AJAX does not have, otherwise, why replace it.
To sum up, the differences are as follows:
Fetch uses Promise instead of callback functions, so it is much easier to write and simpler to write.
Fetch adopts modular design, and API is scattered on multiple objects (Response object, Request object, Headers object), which is more reasonable; by contrast, the API design of XMLHttpRequest is not very good, input, output and state are all managed in the same interface, so it is easy to write very confusing code.
Fetch processes data through data streams (Stream objects) and can be read in blocks, which helps to improve website performance and reduce memory footprint. It is very useful for scenarios where large files are requested or the network speed is slow. XMLHTTPRequest objects do not support data flow. All data must be placed in the cache, and block reading is not supported. You must wait for all of them to be obtained, and then spit them out at once.
Fetch is quite in line with the trend, at the very least, we can write a lot less callback functions, and the forced grid of the code can be improved.
The usage of Fetch
The fetch () method must accept one parameter-- the path to the resource. Whether the request is successful or not, it returns a Promise object, and the resolve corresponds to the Response of the request. The basic syntax is as follows:
Fetch (url). Then (...). Catch (...) The above is all the content of this article "what's the use of Fetch?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.