开发者

Questions about jQuery getScript

Is it better (in any way) to use jQuery's getScript to load the external JS than linking the javascripts manually 开发者_开发问答in the html?


If the javascript file you want to load is somewhat optional, e.g. for a specific browser or maybe geolocation, i'd use getScript; otherwise I'd see no need to push the 'include' further down in the page loading process than a plain html script.

If you are concerned about performance, i would guess that the 'plain-method' is faster, but I haven't tested it. For web page load time performance tuning, there is a nice tool, called yslow, which is a firebug extension.


You may want to delay loading and executing the script until you need it - the page will load faster if it is loaded dynamically.
In addition, the callback is very handy.


Can you rephrase the question? Linking them manually in the html? You mean, the urls to the scripts? You could generate them with your back-end (whatever that may be)... but... of course you need a url to load a script and jQuery can't -- I don't know -- guess or something :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜