很多网站都有使用CNZZ用于统计网站的访问量和访问情况,也有很多站长遇到过因为CNZZ统计代码加载缓慢而影响页面打开效果的情况。
下面分享一个使统计代码延迟加载的代码,引用后不会再因为统计代码无法加载而影响网站打开速度。
<script type="text/javascript">document.write(unescape("%3Cspan id='cnzz_stat_icon_1277943602'%3E%3C/span%3E%3Cscript src='https://s9.cnzz.com/z_stat.php%3Fid%3D1277943602' type='text/javascript'%3E%3C/script%3E"));</script>
<span id='cnzz_stat_icon_123456789'></span>
<script type="text/javascript">
window.onload = function() {
var cz = document.createElement("script");
cz.src = "//s9.cnzz.com/z_stat.php?id=123456789";
document.getElementsByTagName('body')[0].appendChild(cz);
}
</script>
<span id='cnzz_stat_icon_123456789'></span>
<script type="text/javascript">
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = function() {
var cz = document.createElement("script");
cz.src = "//s9.cnzz.com/z_stat.php?id=123456789";
document.getElementsByTagName('body')[0].appendChild(cz);
}
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
var cz = document.createElement("script");
cz.src = "//s9.cnzz.com/z_stat.php?id=123456789";
document.getElementsByTagName('body')[0].appendChild(cz);
}
}
</script>
<span id='cnzz_stat_icon_123456789'></span>
<script type="text/javascript">
$(function() {
var cz = document.createElement("script");
cz.src = "//s9.cnzz.com/z_stat.php?id=123456789";
document.getElementsByTagName('body')[0].appendChild(cz);
});
</script>
<span id='cnzz_stat_icon_123456789'></span>
<script type="text/javascript">
if (typeof jQuery != "undefined" && typeof $ != 'undefined') {
$(function() {
cnzz_stat_func();
});
} else {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = function() {
cnzz_stat_func();
}
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
cnzz_stat_func();
}
}
}
function cnzz_stat_func() {
var cz = document.createElement("script");
cz.src = "//s9.cnzz.com/z_stat.php?id=123456789";
document.getElementsByTagName('body')[0].appendChild(cz);
}
</script>
<div style="display: none;">
<script type="text/javascript">
...
</script>
</div>
本文由 新逸Cary 创作,如果您觉得本文不错,请随意赞赏
采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
原文链接:https://blog.xinac.cn/archives/cnzz-lazy-load.html
最后更新:2020-06-15 10:31:34
Update your browser to view this website correctly. Update my browser now