Preload js code of css or javascript_javascript tips
WBOYOriginal
2016-05-16 18:28:501098browse
There are generally two common ways to preload files: xhr and dynamically inserting nodes. Dynamically inserting nodes is the simplest and most widespread asynchronous loading method (such as yui's Get module). Then files loaded using the dynamically inserted node method will be executed immediately after loading. On the one hand, the execution of javascript will occupy the browser's js execution. The process, on the other hand, may also change the page structure, and the execution of css is more likely to change the entire page. Although the xhr method will not execute scripts, due to the restrictions of the same domain, and the static files of the website are now deployed on the CDN server, how to preload css js files has become a bit mysterious.
A few notes: 1. The reason why new Image().src cannot be used in ff is because ff implements a separate cache for images. At the same time, safari and chrome don't seem to be cached.
2. The dynamically inserted object tag needs to be inserted into the non-head part to trigger loading.
3. ie7 ie8 can also use dynamic objects to load files through some code (mentioned in the code comments). However, the author found that object usually consumes a lot of money, so...
Through his own experiments, he found that it is quite good. Students in need may wish to give it a try.
Statement:
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