Skip to content

Instantly share code, notes, and snippets.

@ambar
Created December 21, 2011 12:32
Show Gist options
  • Save ambar/1505881 to your computer and use it in GitHub Desktop.
Save ambar/1505881 to your computer and use it in GitHub Desktop.
如何改善百度统计引入代码
<html>
<head>
<title></title>
</head>
<body>
<div>
<script>
document.body.appendChild( document.createElement('script') )
</script>
</div>
</body>
</html>
(function(doc,id) {
var t = doc.createElement('script');
t.async = true;
t.src = '//hm.baidu.com/h.js?'+id;
(doc.head || doc.body).appendChild(t);
})(document,'baidu_hash_id')
(function(doc,tag,src) {
var e = doc.createElement(tag), s = doc.getElementsByTagName(tag)[0]; e.async = e.src = src; s.parentNode.insertBefore(e, s);
})(document,'script','//domain/analytics.js')
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fhash_id' type='text/javascript'%3E%3C/script%3E"));
require 'sinatra'
get '/h.js' do
sleep(2)
content_type 'application/javascript'
<<-js
(function (msg) {
var now = function () { return +new Date() }
var begin = now();
while (now() - begin < 2000) {}
console.log(msg, now());
})('h.js loaded. ');
js
end
@guorenxi
Copy link

guorenxi commented Feb 6, 2022

Great.

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