wordpress速度优化 为服务器减压的技巧总结

建站 码拜 9年前 (2015-08-23) 1550次浏览 0个评论

wordpress 的功能很强大,插件支持也很广泛,但是仍然有很多性能优化余地,比如较高的服务器占用,和访问速度。用wordpress做CMS站点时,可以从以下方面去执行wordpress速度优化,为服务器减压!

时间就是生命,等待就是煎熬,速度就是用户体验!

1.Cookie的静态化制作

约有80%至90%的时间,访客要花费大量的时间等待WordPress加载静态内容。如:图像,CSS,JS脚本,flash等。所以你可以优化内容,更快捷地让WordPress加载一个cookie域。消除负载时珍贵的时间,当然这可能看起来并不多。

wordpress只要修改一下wp-config.php就好了!

在合适的位置加入

define(“WP_CONTENT_URL”, “http://static.***.com”);

define(“COOKIE_DOMAIN”, “www.***.com”);

然后用用“bloginfo(template_directory’)”这段代码加入你要实现的静态内容中即可!

2.设置静态内容缓存

用相关的缓存插件也需要这个步骤,修改.htaccess文件

代码如下:

<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault      “access plus 1 month”
# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest “access plus 0 seconds”
# Your document html
ExpiresByType text/html “access plus 0 seconds”
# Data
ExpiresByType text/xml “access plus 0 seconds”
ExpiresByType application/xml “access plus 0 seconds”
ExpiresByType application/json “access plus 0 seconds”
# RSS feed
ExpiresByType application/rss+xml “access plus 1 hour”
# Favicon (cannot be renamed)
ExpiresByType image/x-icon “access plus 1 week”
# Media: images, video, audio
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/jpg “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType video/ogg “access plus 1 month”
ExpiresByType audio/ogg “access plus 1 month”
ExpiresByType video/mp4 “access plus 1 month”
ExpiresByType video/webm “access plus 1 month”
# HTC files  (css3pie)
ExpiresByType text/x-component “access plus 1 month”
# Webfonts
ExpiresByType font/truetype “access plus 1 month”
ExpiresByType font/opentype “access plus 1 month”
ExpiresByType application/x-font-woff   “access plus 1 month”
ExpiresByType image/svg+xml “access plus 1 month”
ExpiresByType application/vnd.ms-fontobject “access plus 1 month”
# CSS and JavaScript
ExpiresByType text/css “access plus 1 year”
ExpiresByType application/javascript “access plus 1 year”
ExpiresByType text/javascript “access plus 1 year”
<IfModule mod_headers.c>
Header append Cache-Control “public”
</IfModule>
</IfModule>

3.优化数据库

WordPress的免费插件即可解决 ,Yoast Optimize DB和WP DB Manager。

4.尽量缓存媒体文件

创建缓存可以很简单地通过插件完成。推荐缓存工具:WP Super Cache, Hyper Cache,和W3 Total Cache。用这些生成HTML文件,可以节省很多时间。

5.CDN加速

cdn一般是收费,不过也有免费的CDN。

推荐一些免费CDN:Webluker,cloudflare

6.压缩JS和CSS文件

JS压缩工具推荐:Closure Compiler ,Minify JavaScript. CSS压缩工具推荐:Minify CSS ,CSS Compressor

7.压缩图像

图像的加载可以算是最耗时的,用BMP或者PSD作为图像速度会更慢,建议尽量使用JPG压缩。优化图片的好处是显而易见的,首先可以节省大量的带宽资源;其次,图片优化,可以大大提供博客整体的载入速度。

8.GZIP压缩

GZIP的压缩在一定限度内是很不错的!而且通过gzip压缩还可以屏蔽广告,GZIP的压缩代码如下:修改.htaccess文件

<IfModule mod_deflate.c>
# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)s*,?s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare   COMPRESS
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
FilterChain     COMPRESS
FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>

9.禁用ETAGS

在.htaccess 文件中加这一行!

File ETag none

10.服务器环境

使用LAMP或LNMP环境,可以更好的支持wordpress并且风险系数低,也很安全,估计你的服务器或者VPS几年都不会重启一次!

11 删除无价值的插件

插件是致使WordPress博客访问速度变慢的主要杀手之一,能少用就少用

总结:

这些方法中大多数只适合在LAMP或者LNMP的环境下,所以使用wordpress最好在linux环境下!如何优化提高WordPress的访问速度,这是有极限的,如果使用的主机质量本身有很大的问题,那即使再好的优化,也是没效果的。所以选购一款好的WordPress主机是绝对必要的。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明wordpress速度优化 为服务器减压的技巧总结
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!