文章目录
  1. 1. 本博情况
  2. 2. 必不可少的罗嗦
  3. 3. 清理没用的服务
    1. 3.1. 去除Disqus评论
    2. 3.2. 去掉Github仓库展示
    3. 3.3. 去除Twitter按钮
    4. 3.4. 去除Google+相关
    5. 3.5. 去除Pinboard服务
    6. 3.6. 去除Delicious评论,去除后可能没有评论系统
    7. 3.7. 去除Facebook Like
  4. 4. 替换快速的请求资源
    1. 4.1. 解决Google Analytics巨慢的问题
    2. 4.2. 解决fonts.googleapis.com蜗牛慢
    3. 4.3. 解决ajax.googleapis.com慢的问题
  5. 5. In Conclusion

解决Octopress博客访问慢的问题

本博情况

  • 前身为 marujun.github.io
  • 新域名 devma.cn 从阿里云购买。
  • DNS由DNSPod解析。
  • 内容存放在Github、Coding的Pages上。
  • 博客系统为Octopress

必不可少的罗嗦

买了这个域名已经一周了,发现国内访问还是超级慢,慢的让人无法接收了,当然具体原因,大家都懂得。于是只好自己修改Octopress程序了。修改之前的访问速度以分钟计数。修改完成之后,秒开了有木有。

清理没用的服务

以下修改均修改 _config.yml ,以下可以根据自己的需要进行去除。

去除Disqus评论

打开文件找到 Disqus Comments ,按照下面在每一行前面加#注释掉即可。

1
2
3
# Disqus Comments
#disqus_short_name: androidyue
#disqus_show_comment_count: true

去掉Github仓库展示

1
2
3
4
5
# Github repositories
#github_user: androidyue
#github_repo_count: 11
#github_show_profile_link: true
#github_skip_forks: true

去除Twitter按钮

1
2
3
# Twitter
#twitter_user:
#twitter_tweet_button: true

去除Google+相关

1
2
3
4
5
6
7
# Google +1
#google_plus_one: true
#google_plus_one_size: medium<br />
# Google Plus Profile
# Hidden: No visible button, just add author information to search results
#googleplus_user: 105362551238192049560
#googleplus_hidden: false

去除Pinboard服务

1
2
3
# Pinboard
#pinboard_user:
#pinboard_count: 3

去除Delicious评论,去除后可能没有评论系统

1
2
3
# Delicious
#delicious_user:
#delicious_count: 3

去除Facebook Like

1
2
# Facebook Like
#facebook_like: true

替换快速的请求资源

其实,真正解决加速的重要环节可能是这里,因为Octopress很多依赖于Google的库和资源。

解决Google Analytics巨慢的问题

对于使用Google Analytics来说,加在ga.js这个文件简直是要命的慢,这里我使用自己存放在七牛CDN上的js. http://droidyue-tools.qiniudn.com/ga.js 已验证,完全可以正常收集数据。

参考如下,修改 source/_includes/google_analytics.html

1
2
3
4
5
6
7
8
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src='http://droidyue-tools.qiniudn.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

解决fonts.googleapis.com蜗牛慢

这里我们使用数字公司提供的Google Fonts大陆解决方案,使用 fonts.useso.com 替换fonts.googleapis.com

修改文件 /source/_includes/custom/head.html

1
2
3
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.useso.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.useso.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">

解决ajax.googleapis.com慢的问题

修改 source/_includes/head.html

1
2
3
4
5
6
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="技术小黑屋" type="application/atom+xml">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="//ajax.useso.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>

In Conclusion

导致网站慢的原因其实是加载Google的资源,当然我们不能怨Google.经过测试,使用数字公司的解决方法之后,国内国外访问速度都是可以的。这里还是推荐一下数字公司的这个解决方案http://libs.useso.com/