Skip to content

Instantly share code, notes, and snippets.

@swainet
Last active December 17, 2015 21:39
Show Gist options
  • Save swainet/5676032 to your computer and use it in GitHub Desktop.
Save swainet/5676032 to your computer and use it in GitHub Desktop.
网速检测
window.addEventListener('load', function () {
var interval = 500, begin = Date.now(), img = new Image(), timer = setTimeout(handler, interval);
window.removeEventListener('load', arguments.callee);
img.addEventListener('load', handler, false);
img.src = 'https://i.alipayobjects.com/e/201305/Q9jNoeIir.gif?t=' + begin;
function handler() {
clearTimeout(timer);
img.removeEventListener('load', handler);
//响应在500ms以内算高速网络 高清(HD)标清(SD)
document.body.className = (document.body.className + (Date.now() - begin < interval ? ' ui-hd' : ' ui-sd')).trim();
}
}, false);
window.addEventListener("load",function(){var interval=500,begin=Date.now(),img=new Image,timer=setTimeout(handler,interval);window.removeEventListener("load",arguments.callee);img.addEventListener("load",handler,false);img.src="https://i.alipayobjects.com/e/201305/Q9jNoeIir.gif?t="+begin;function handler(){clearTimeout(timer);img.removeEventListener("load",handler);document.body.className=(document.body.className+(Date.now()-begin<interval?" ui-hd":" ui-sd")).trim()}},false);
@hotoo
Copy link

hotoo commented Nov 4, 2013

请将图片移动到用户本地不缓存的 user-nocache 目录,并移除随机参数。

例如:

https://i.alipayobjects.com/user-nocache/nocache.png

https://a.alipayobjects.com/user-nocache/nocache.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment