This method is a method provided by jquery itself for dynamically loading js. When a website needs to load a large amount of js, dynamically loading js is a better method. When a certain function is needed, the corresponding js is loaded. However, I found some dissatisfaction during use.
Every time you need to execute this function, you will request this js. Isn’t this a disservice? So I found the API description of Jquery official website http://api.jquery.com/jQuery.getScript/ In fact, this method is an encapsulation of the ajax method. You can use the cache of the ajax method to change the http status 200 into 304, thus using the client's cache:
So, you will find that every time you call this function, it becomes as follows:
Every time js is called, the following parameters like "?_=13126578" are gone, and the status is Not Modified. But I am a bit of a germophobe. Every time I use this function, although the server no longer needs to return the entire js file, it still has to request the server every time, which always makes me feel uncomfortable. Hence the title of this blog was born. Without further ado, let’s start with the code:
At this point, the entire transformation is completed. When you use this function, It will only send a js request to the server once during initialization, and after the loading is completed, it will not request the server again, even if it is a 304 status code.
I am a newbie in js, please give me a pat, O(∩_∩)O~
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