强迫症又犯了-继续优化下博客

测试地址:https://gtmetrix.com/reports/shikey.com/Bw7asFob

20161224133914

20161224134019

发现了一个问题:可以看错来用户浏览器缓存没有做。

20161224134048

整体还算满意;

先做下预缓存吧:

我参考的是老外这篇文章

https://varvy.com/pagespeed/leverage-browser-caching.html

设置browser cache来加速网站(Leverage browser caching)

直接在你的网站的根目录下找到.htaccess,用Notpad++来编辑(不要使用windows自带的记事本,以免出错),加上如下代码:

  1. ## EXPIRES CACHING ##
  2. ExpiresActive On
  3. ExpiresByType text/css A31536000
  4. ExpiresByType application/x-javascript A31536000
  5. ExpiresByType text/x-component A31536000
  6. ExpiresByType text/html A3600
  7. ExpiresByType text/richtext A3600
  8. ExpiresByType image/svg+xml A3600
  9. ExpiresByType text/plain A3600
  10. ExpiresByType text/xsd A3600
  11. ExpiresByType text/xsl A3600
  12. ExpiresByType text/xml A3600
  13. ExpiresByType video/asf A31536000
  14. ExpiresByType video/avi A31536000
  15. ExpiresByType image/bmp A31536000
  16. ExpiresByType application/java A31536000
  17. ExpiresByType video/divx A31536000
  18. ExpiresByType application/msword A31536000
  19. ExpiresByType application/vnd.ms-fontobject A31536000
  20. ExpiresByType application/x-msdownload A31536000
  21. ExpiresByType image/gif A31536000
  22. ExpiresByType application/x-gzip A31536000
  23. ExpiresByType image/x-icon A31536000
  24. ExpiresByType image/jpeg A31536000
  25. ExpiresByType application/vnd.ms-access A31536000
  26. ExpiresByType audio/midi A31536000
  27. ExpiresByType video/quicktime A31536000
  28. ExpiresByType audio/mpeg A31536000
  29. ExpiresByType video/mp4 A31536000
  30. ExpiresByType video/mpeg A31536000
  31. ExpiresByType application/vnd.ms-project A31536000
  32. ExpiresByType application/x-font-otf A31536000
  33. ExpiresByType application/vnd.oasis.opendocument.database A31536000
  34. ExpiresByType application/vnd.oasis.opendocument.chart A31536000
  35. ExpiresByType application/vnd.oasis.opendocument.formula A31536000
  36. ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
  37. ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
  38. ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
  39. ExpiresByType application/vnd.oasis.opendocument.text A31536000
  40. ExpiresByType audio/ogg A31536000
  41. ExpiresByType application/pdf A31536000
  42. ExpiresByType image/png A31536000
  43. ExpiresByType application/vnd.ms-powerpoint A31536000
  44. ExpiresByType audio/x-realaudio A31536000
  45. ExpiresByType image/svg+xml A31536000
  46. ExpiresByType application/x-shockwave-flash A31536000
  47. ExpiresByType application/x-tar A31536000
  48. ExpiresByType image/tiff A31536000
  49. ExpiresByType application/x-font-ttf A31536000
  50. ExpiresByType audio/wav A31536000
  51. ExpiresByType audio/wma A31536000
  52. ExpiresByType application/vnd.ms-write A31536000
  53. ExpiresByType application/vnd.ms-excel A31536000
  54. ExpiresByType application/zip A31536000
  55. ## EXPIRES CACHING ##
  56. 代码2(建议新手使用,我使用的就是这段代码)
  57. ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg “access 1 year”
    ExpiresByType image/jpeg “access 1 year”
    ExpiresByType image/gif “access 1 year”
    ExpiresByType image/png “access 1 year”
    ExpiresByType text/css “access 1 month”
    ExpiresByType text/html “access 1 month”
    ExpiresByType application/pdf “access 1 month”
    ExpiresByType text/x-javascript “access 1 month”
    ExpiresByType application/x-shockwave-flash “access 1 month”
    ExpiresByType image/x-icon “access 1 year”
    ExpiresDefault “access 1 month”
    </IfModule>
    ## EXPIRES CACHING ##

重新测试一下得分:

 

显示得分已经为A,一切正常;

20161224134114

20161224134205

另外页面加载的js、css文件过多,其中腾讯微博加载速度过慢。我使用的是这款插件WP MINIFY STATIC,直接在wordpress插件后台搜索即可安装

原理是将css、js文件合并缩减体积,加快加载速度,其实百度云加速也有这个功能

另外将css和、js等静态文件放到又拍云或者七牛云,使用wpsurpercache的cdn功能可能效果更好,但是不像折腾了

我的vps是2M独享相信速度也慢不到哪里去。

20161224163304

测试压缩了大概35%左右的体积,效果还不错。

测试一下全国加载速度,貌似云南不行,因为加上cdn的话其他区域访问会变慢

而且是个个人博客,所以无所谓了。

20161224163848

去掉cdn之后的对比图:

20161224164315

下载速度对比,我用的中原电信CBS,貌似速度还不错。感觉不准~!!!!

20161224164620

 

至此基本上折腾的差不多了,至于freedomain-cookies,下次有机会再弄吧。

记录一下,希望对大家有所帮助。

原创文章,转载请注明: 转载自天下无鱼

本文链接地址: 强迫症又犯了-继续优化下博客