admin管理员组文章数量:1392007
I am nearly done with my site and am optimising it at the moment; I would like to know the best and fastest way to include all my external javascript files. I want the site to download as quick as possible, but it has quite a few (10 or so) external javascript files that need to be loaded; some are jQuery library files from Google's AJAX API and some are mine.
I'm sure I read a while ago that I could call all external scripts using a bit of javascript code, in effect, only calling one external file from the browsers point of view.
Do you see what I mean?
Many thanks
I am nearly done with my site and am optimising it at the moment; I would like to know the best and fastest way to include all my external javascript files. I want the site to download as quick as possible, but it has quite a few (10 or so) external javascript files that need to be loaded; some are jQuery library files from Google's AJAX API and some are mine.
I'm sure I read a while ago that I could call all external scripts using a bit of javascript code, in effect, only calling one external file from the browsers point of view.
Do you see what I mean?
Many thanks
Share Improve this question edited Aug 5, 2009 at 3:00 hughdbrown 49.1k20 gold badges88 silver badges111 bronze badges asked Apr 15, 2009 at 22:43 ZanderZander 2,6844 gold badges33 silver badges56 bronze badges4 Answers
Reset to default 8- Combine all your Javascript into one external file (you can do this dynamically and save the cached result);
- Minify that file;
- Version that file (I use the mtime of a preconfigured file for this);
- Gzip the file if the client supports that; and
- Use a far futures Expires header on the file.
What you're referring to (using Google's AJAX Libraries service) is another way to handle this that falls under the heading of a CDN (Content Delivery Network). The idea being that the file is stored in multiple plallllces and the client will download the closest (and that result will be saved).
That's hard or just awkward to bine with other techniques and I've found that doing multiple external loads this way pletely erodes any perceived benefit (unless that's your only external load) so I use the method listed above instead.
My guess is to bine the library files to just one file (except the ones hosted at Google). Each call to your server takes quite some resources, so you're better off with just one call. You can even bine the files online:
http://yui.2clics/
I would suggest merging all the scripts together into one JS file, and then using the YUI Compressor to pack them into a smaller file.
To use scripts browser has to download them anyway so I don't think there is any difference how do you call them... unless you use pressing on server and depressing on client side.
本文标签: What is the bestfastest way to include my external javascripts I use jQueryStack Overflow
版权声明:本文标题:What is the bestfastest way to include my external javascripts? I use jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767612a2624136.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论