I encountered a similar problem during the interview. The general idea is that when loading the page, some js file resources will be loaded using script tags. If these resources are not requested back for a long time, how to manually terminate the request?
I know that Ajax requests have an abort method. I wonder if the interviewer wants to ask this, and is there any other way to terminate the request?
Thanks for the invitation.
Like @小Stream said, it’s timeout.
The rough implementation idea is as follows:
In the above example, queue loading is performed at intervals of 25 milliseconds, and the loading time is within 100ms.
What should be examined is the timeout of loading resources
The loading of
is always synchronous (blocking) and cannot be affected by DOM operations. What the subject needs isasynchronous JS loadingthat is independent of page loading and rendering. There are many tools, here is an example of RequireJS:
HTML page:
Save as
test1.js
: