来自CDN(Google)的流式jquery(JS文件) [英] Streaming jquery(JS files) from a CDN (Google)

查看:196
本文介绍了来自CDN(Google)的流式jquery(JS文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个不做功课的情况。:-)

This one is a case of not doing your homework.:-)

除了动态加载优势外,是否有意义包含一个JavaScript库(jQuery in我的情况)来自谷歌服务器,当我可以从我的服务器加载它作为一个单独的文件,包括19kb jQuery zip文件+我编写的附加JavaScript代码 - 所有压缩与JS压缩器,并提供HTTP放气。

Apart from dynamic loading advantage, does it make sense to include a JavaScript library(jQuery in my case ) from a Google server when I can load it from my server as a single file comprised of the 19kb jQuery zip file + the additional JavaScript code I have written – all compressed with a JS compressor and served HTTP deflated.

使用Google服务器,我将有2次(并行)HTTP往返。一个用于获取jquery文件,另一个用于获取站点JavaScript代码。一个19kb,另一个说20-25kb。
在正常情况下,从我的网站下载一次30-35kb。

With Google server I’ll have 2(parallel) HTTP round trips. One to get the jquery file and the other to get the site JavaScript code. One 19kb and the other say 20-25kb. Under normal circumstances it would be a single 30-35kb download from my site.

推荐答案

考虑一下jQuery脚本从谷歌CDN下载可能已经缓存在访问者的浏览器上,因为它具有一致的标题和缓存控制,无论从哪里下载。因此,平均而言,大多数用户只需下载特定于站点的JavaScript脚本。此外,CDN通常比单个服务器具有更快的响应时间,因为它们从离您所在位置最近的服务器做出响应。

Consider that a jQuery script downloaded from the google CDN might well already be cached on a visitor's browser, since it has consistent headers and cache control no matter where it is downloaded from. Hence, on average most users will only have to download your site-specific javascript scripts. Also, CDN generally have faster response times than single servers, since they respond from a server nearest to your location.

对于您的问题,没有任何简洁的回答,如这两种方法都能在现代连接上提供良您应该在胁迫下对系统进行分析,看看哪种解决方案能够提供最佳结果(如果需要进行此类优化)。

There is no cut and dry answer to your question, as both approaches offer good performance on modern connections. You should profile your system under duress and see what solution offers the best results (and if such optimization is even needed).

这篇关于来自CDN(Google)的流式jquery(JS文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆