This article is a mirror article of machine translation, please click here to jump to the original article.

View: 79|Reply: 0

[JavaScript] Front-end Performance Optimization: Ditch XMLHttpRequest in favor of fetch interfaces

[Copy link]
Posted on 3/2/2026 9:02:01 AM | | | |
Requirements: In the case of homologous origin, the frontend sends GET and POST requests to the backend interface, because the interface is public, it does not need to carry any authentication information, for example: when requesting cookie information, when using XMLHttpRequest, no matter how it is configured, the request cookie information cannot be deleted, which will cause the content of the request package to become larger, and it also wastes backend resources to parse, which is meaningless.

Whether you use native XMLHttpRequest or jQuery's Ajax to send a request to the backend, the cookie information of the request cannot be removed in the case of homologous, and the code is as follows:
BecausewithCredentials is designed for cross-domain。 As shown below:



Or carry cookies, wasting resource bandwidth and backend resources

After modifying with fetch, the code looks like this:
The credentials are configured as follows:

omit: Never send credentials in a request and do not include credentials in a response.
same-origin(default): Only credentials that are sent and contain the same origin request.
include: Even for cross-domain access, be sure to include credentials.

Test request, very clean and refreshing, as shown below:



Reference:The hyperlink login is visible.




Previous:.NET/C# class libraries reference and use ASP.NET Core API methods
Next:UNIX Domain Socket (UDS) over TCP communication
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com