如何禁用低带宽连接的jQuery include [英] How can I disable a jquery include for low bandwidth connections

查看:86
本文介绍了如何禁用低带宽连接的jQuery include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的网站,该网站很少使用jquery,但这不是必需的,所以我想如果用户连接速度较慢,请跳过jquery下载.

I have a simple website which makes a little use of jquery but it is not essential so I would like to skip the jquery download if the users connection is slow.

理想情况下,我会检测到连接速度较慢,但​​我想检测到手机可能是对此的合理代理.

Ideally I would detect a slow connection but I suppose detecting a mobile phone might be a reasonable proxy for this.

如果可能的话,我将删除使用jquery的页面部分,并在加载jquery时动态添加它们.

If this is possible I would then remove the parts of the page which use jquery and add them dynamically if jquery is loaded.

我考虑的选项是:

  • 通过下载小图片测试连接速度
  • 下载jquery但在大约一秒钟后超时(我搜索了取消下载,但一无所获)
  • 将jquery放在一起,然后只写我需要的javascript(不过,对于某些浏览器,我可能会弄错它)
  • 将jQuery下载包裹在某些javascript中,以检查userriod或iphone的用户代理
  • 尝试使用CSS媒体选择器控制jquery的下载

但是我不确定该说服哪个.

but I am not sure which to persue.

此外,我不能使用服务器端的技巧,因为它是静态页面(以避免appengine冷启动问题).

Also, I can't use server side tricks as it is a static page (to avoid the appengine cold start issue).

推荐答案

我倾向于说算了.

任何严格的速度测试都需要传输比jQuery库更重要的数据.

Any serious speed test will need to transfer more data than the jQuery library weighs.

您可以为用户提供一个选择(例如开放式低带宽网站")并将该选择存储在cookie中.然后,您可以检查cookie的值,并在服务器端动态嵌入或不嵌入jQuery,或使用@banjomonster对

You could give users a choice (like "open low-bandwidth web site") and store that choice in a cookie. You could then check the cookie's value, and embed or not embed jQuery dynamically on server side, or using JavaScript as shown in @banjomonster's answer to this question.

除此之外,我将继续进行介绍.如果您从Google的CDN中添加它,则很可能它已经存在于用户的浏览器中,而不必再次加载.

Other than that, I would just go ahead and include it. If you include it from Google's CDN, chances are it is in the user's browser already anyway, and doesn't have to be loaded again.

这篇关于如何禁用低带宽连接的jQuery include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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