Created
December 21, 2011 12:32
-
-
Save ambar/1505881 to your computer and use it in GitHub Desktop.
如何改善百度统计引入代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<div> | |
<script> | |
document.body.appendChild( document.createElement('script') ) | |
</script> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool,不过见过一个更好的解决方法,是: