问题描述
有许多插件可以预加载图片,但有没有办法预加载javascript?我的应用程序使用一个大的js文件,在页面显示之前加载大约需要5秒左右...所以,有什么方法可以显示加载消息而我以某种方式预加载脚本? (有点像'加载......'就像在Gmail中一样)
There are numerous plug-ins to preload images, but is there a way to preload javascript? My application uses a big js file and it take about 5 seconds or so to load before the page shows... so, is there a way I can display a "loading message" while I somehow preload the script? (A sort of 'Loading...' like in Gmail)
谢谢
推荐答案
$.getScript('script.js',function(){
//this is your callback function to execute after the script loads
});
getScript应该可以正常工作。当脚本加载时(我假设在一个动作或什么东西?)显示加载消息并调用getScript,然后在回调区域中,将加载的文本更改为完成并执行您想要的任何内容。
getScript should work fine. While the script is loading (I assume on an action or something?) show the loading message and call getScript, then in the callback area, change the text that says "loading" to "done" and execute whatever you want.
这篇关于预加载脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!