- 浏览: 142521 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (135)
- Liferay (12)
- Alfresco (12)
- SIP (1)
- MFTV (7)
- Server (1)
- JVM (1)
- AR (1)
- Agile (1)
- DirectX (2)
- OTP (1)
- Windows (7)
- Electronic (1)
- Wowza (1)
- Documentum (1)
- CMIS (1)
- MCUMediaServer (2)
- Linux (1)
- LBS (1)
- Product Lifecycle Management (1)
- Robot (1)
- XBMC (4)
- Andriod (2)
- Boxee (2)
- Graphic (1)
- GPU (1)
- Openmeeting (2)
- Conference (2)
- GitHub (1)
- iOS (1)
- 越狱 (1)
- OpenELEC (2)
- WIFI (1)
- Big Blue Button (3)
- Sakai (1)
- Redmine (1)
- 联盟营销 (1)
- OpenSplash (1)
- MONO (1)
- HTML5 (1)
- AirPlay (1)
- PHPMotion (1)
- Java (1)
- Maven (1)
- Proxy (1)
- JDK (1)
- Mac (1)
- REST (1)
- JSON (1)
- IT互联网 (1)
最新评论
http://www.delishost.com/2012/01/tuning-your-phpmotion-theme-for-performance/
Tuning your PHPmotion theme for performance
Nothing is worse then having to wait for a website to load and speed is even more important when your website has huge competitors such as Youtube and Dailymotion. Here we’ll take you through the steps to making your PHPmotion website load faster.
Note: These changes are based on the default theme, but should be applicable to custom themes with a few minor adjustments. Tests are measured on the home page, but will improve the entire site.
Scores are measured with the excellent YSlow! plugin for Firefox and Chrome .
The Test Case: phpmotionperformance.delishost.com
- Default PHPmotion V3.5 installation
- Some uploaded content to fill the site.
- Total page size: 465KB
- YSlow! Rating: C
- Page loaded in 6.40s
Warning: Always keep copies and backups of any files you modify!
Step 1: Host it close-by.
The closer your website is to your visitors the better, latency is reduced meaning files are transferred faster as the delay between connecting to the server and actually receiving the file is reduced.
If your main visitors are in the USA, then choosing a server there is an obvious choice. The same goes for hosting in Europe, having your site hosted with the correct host can make a noticeable difference to your end users. We offer fast, reliable hosting in European datacentres .
Step 2: Optimize your javascript and CSS files
To speed a site up we need to minimize the amount of bytes that are actually transferred from the server to the visitor’s browser. To do so we can compress all the javascript and CSS files that aren’t currently optimized.
Useful online tools for compressing files include:
- Online YUI Compressor (Javascript & CSS)
- Google Closure Compiler Service (Javascript only)
- CSS Compressor (CSS only)
This is a fairly simple step, simply search through your site for javascript and css files. The main places to look include:
- javascripts/
- css/
- themes/yourthemes/css/
Now upload these files one by one to the appropriate site from the above links. Make sure you’re not trying to compress an already compressed file. You can check this by opening the file, if everything looks like a solid block or a single line of text then it is already compressed.
Download their optimized versions and replace the file on the website.
Remember to keep a backup of each file and test the site functions after each change. As compressing can occasionally break Javascript functions so parts of your site will appear to stop working.
Step 3: Using DEFLATE to compress content
DEFLATE is an excellent way to reduce the amount of content that is sent to the browser. It works by compressing non binary files and sending the compressed versions to the visitor. Their browser then uncompresses and loads the content.
Enabling DEFLATE is pretty simple and definitely worth it. Open your .htaccess file and paste the following:
-
# DEFLATE
-
<IfModule mod_deflate.c>
-
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/html text/plain text/css text/xml
-
</IfModule>
-
# End DEFLATE
Now upload your new .htaccess file and clear your browser cache (otherwise YSlow! may incorrectly report that it isn’t working). The total page size (no other changes) is now 218KB (53% savings! )
Step 4: Building a CDN
We’ll now concentrate on setting up a basic CDN. Many browsers limit parallel HTTP requests to two by domain. The default home page for our test site has 40 components which can only be downloaded 2 by 2. Setting up CDNs will allow us to multiple the maximum number of parallel requests and thus noticeably speed up the entire website.
In the following examples replace example.com
with your website domain name and /phpmotionpath/
with the path to your PHPmotion installation.
Here I will walk you through how to create the following:
- theme.example.com for theme stylesheets (themes/yourtheme/css/)
- css.example.com for non theme related stylesheets (css/)
- js.example.com for javascript files (js/)
- thumbs.example.com for video thumbnails (uploads/thumbs/)
You will be able to take this further if you wish, but these should already help load times on your website quite a bit.
To continue you will need a code editor that is capable of doing a search/replace across files otherwise you will spend a lot of time going through the files.
To make updates to CDN names easier in the future I have created a
PHP file which will hold all CDN names in an array for easy re-use in
the templates. Copy and save the following code into addons/dh-cdn.php
.
-
<?php
-
/**
-
* @author Ben Newman http://www.delishost.com
-
*
-
* This file simply holds variables for the different cdn names you can use in
-
* your themes. It allows you to add/modify CDNs without having to go through all
-
* your templates.
-
*
-
* You can access these through in the templates like so:
-
* [var.asset_cdn.theme]
-
*/
-
$asset_cdn = array(
-
'theme' => 'http://theme.example.com ', // To load theme assets
-
'cdn' => 'http://cdn.example.com ', // Mirrors the normal PHPmotion path
-
'js' => 'http://js.example.com ', // Loads the javascript files
-
'videothumbs' => 'http://thumbs.example.com ', // Loads thumbs from uploads/thumbs/
-
);
Upload this file to your server after making sure to enter the correct addresses for each one. Then open classes/config.inc.php
and add the following on a new line before ?>
.
-
include installation_paths().'/addons/dh-cdn.php';
Theme CSS CDN
Create a subdomain called theme.example.com
that points to /phpmotionpath/themes/yourtheme
. Once this is done you can test it is working by trying to load http://theme.example.com/css/main.css
in your browser. If it shows everything is correct then you can continue.
Note: You will need to update this if you switch themes in the future.
Editing themes/yourtheme/templates/main_1.htm
– search for the following strings:
-
[var.base_url]/themes/[var.user_theme]
And replace with:
-
[var.asset_cdn.theme]
Default CDN
The following CDN will point directly to the same directory as your
PHPmotion installation. This allows us to load any PHPmotion files over
the CDN. Create a subdomain cdn.example.com
that points to /phpmotionpath/
.
You will now be able to load any assets you like by simply replacing
the base url with this CDN one. Most strings that need editing are in themes/yourtheme/templates/main_1.htm
.
-
<link href="css/rating_style.css" rel="stylesheet" type="text/css" media="all">
-
<link href="css/thickbox.css" rel="stylesheet" type="text/css" media="screen">
-
<link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all">
-
<link href="javascripts/jquery.jcarousel.css" rel="stylesheet" type="text/css" media="all">
Becomes:
-
<link href="[var.asset_cdn.cdn]/css/rating_style.css" rel="stylesheet" type="text/css" media="all">
-
<link href="[var.asset_cdn.cdn]/css/thickbox.css" rel="stylesheet" type="text/css" media="screen">
-
<link href="[var.asset_cdn.cdn]/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all">
-
<link href="javascripts/jquery.jcarousel.css" rel="stylesheet" type="text/css" media="all">
Leave the javascripts/
one as we’ll use the js CDN for this one.
Javascript CDN
Create a subdomain js.example.com
that points to /phpmotionpath/javascripts/
.
This will allow you to load most of the javascript files. Using your
search/replace function use these two to setup the js cdn.
- Search: “javascripts/
- Replace with: “[var.asset_cdn.js]/
And:
- Search: “[var.base_url]/javascripts/
- Replace with: “[var.asset_cdn.js]/
Video thumbs CDN
Create a subdomain thumbs.example.com
that points to /phpmotionpath/uploads/thumbs/
. We’ll now be able to load all the video thumbs over this CDN.
Search for this string in your template files: "uploads/thumbs/"
and also "[var.base_url]/uploads/thumbs/
Replace with: "[var.asset_cdn.videothumbs]/
Step 5: Expires
The mod_expires Apache module allows you to set how long certain elements should stay cached in a visitors browser. This is a great way to speed up your website as browsers will know not to bother requesting certain content until it has expired.
You have to be careful when using this as changes you make to any
cached content will be ignored. You can get around this by appending ?v=1
to the end of your elements and updating the number each time you make a
change to that element. The browser will then think that it is a new
item and will re-download it.
We’ll set up some basic Expires rules in the /phpmotionpath/.htaccess
file.
-
# Expires
-
<IfModule mod_expires.c>
-
<FilesMatch "\.(gif|png|jpe?g|js|css|ico|swf)$">
-
ExpiresActive On
-
ExpiresDefault "access plus 1 week"
-
</FilesMatch>
-
</IfModule>
-
# End Expires
As you can probably tell from the above example your browser will
know to cache the files one week after their first access. It is a good
idea to only set this up once you’ve finished any theme changes to your
website otherwise you will have to append ?v=X
to all your assets to force them to be flushed from your browser cache.
Step 6: Advanced Optimisations
There are many other ways to improve load performance, but they require more work and knowledge of coding and server management. Here are a few things that you can look into to further optimize performance.
Image sprites
Image sprites are images (usually small theme images) that are grouped together into a single image file then used within the layout with css backgrounds, changing the background-position to display the right image in the right place. If your theme uses a lot of background images this is a fairly simple way to reduce http requests – providing you have a solid knowledge of CSS that is.
Proxy Cache
If you have a VPS or dedicated server you can setup a proxy cache server which will create and cache pages as they are accessed to majorly improve performance as your PHP files won’t even be accessed. This would require some configuration to avoid pages becoming stale and out of date.
Conclusion
Here is the final result after applying the above steps to the same page quite an improvement don’t you agree?
- Total page size: 217KB
- YSlow! Rating: A
- Page loaded in 4.43s
- Handles more parallel HTTP requests for assets
- Decreases bandwidth usage
- Caches assets in the browser with the mod_expires
Page load time has been shortened by a few seconds (the gain will vary depending on the page). Bandwidth usage will be reduced and thanks to caching less http requests mean less server traffic. Caching is also improved which means that repeat visits and any other pages loaded will be much faster.
I hope you found this post useful. If you did please be kind enough to share it. Feel free to leave any questions or suggestions you might have in the comments below.
相关推荐
8.18发烧购物节活动SOP - 电商日化行业+电商引流转化(5张子表全案)
网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip,个人经导师指导并认可通过的高分大作业项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期末大作业基于HTML+CSS的仿中国银行网站源代码.zip网页设计期
ntu嵌入式所有周实验文件
一款可以快速借助ChatGPT,快速生成大量原创有深度文章,快速丰富网站内容,完全免费,新建文章标题跟分类后,点击生成即可自动生成文章,生成后可以点击查看文章直达文章界面,分类可以设置不存在的,程序发现不存在会自动新建。
Adobe Camera Raw(RAW处理工具)v17.1.0.mp4
2024圣诞节倒计时页面源码.mp4
MaixPy机械臂井字棋游戏开发源码-最新开发(可比赛用).zip [资源说明] 1、该项目是团队成员近期最新开发,代码完整,资料齐全,含设计文档等 2、上传的项目源码经过严格测试,功能完善且能正常运行,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的高校学生、教师、科研工作者、行业从业者下载使用,可借鉴学习,也可直接作为毕业设计、课程设计、作业、项目初期立项演示等,也适合小白学习进阶,遇到问题不懂就问,欢迎交流。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 5、不懂配置和运行,可远程教学 欢迎下载,学习使用!
理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip,个人经导师指导并认可通过的毕业设计项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做毕业设计的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基于深度学习的行人重识别系统python源码.zip理工大学本科毕业设计-基
感恩母恩母爱如水母亲节主题班会
基于java的同城宠物喂遛系统设计与实现.docx
乱七八糟聚合类工具箱v1.3.86应有尽有高级版.mp4
安卓一木记账v5.8.90解锁VIP绿化高级版.mp4
Comsol经典小案例。 晶格耦合作用结构色,CIE1931计算与绘制。
2021中国新锐品牌发展研究:食品饮料行业报告
YS9082HP_033_HPS1A30C_N38A
LOL英雄联盟2012怀旧网单.mp4
2020林达阳光新城抖音直播售房脚本
【python上位机开发】(整套源码)
OpenCV部署YOLOv5-pose人体姿态估计(C++和Python双版本).zip [资源说明] 1、该项目是团队成员近期最新开发,代码完整,资料齐全,含设计文档等 2、上传的项目源码经过严格测试,功能完善且能正常运行,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的高校学生、教师、科研工作者、行业从业者下载使用,可借鉴学习,也可直接作为毕业设计、课程设计、作业、项目初期立项演示等,也适合小白学习进阶,遇到问题不懂就问,欢迎交流。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 5、不懂配置和运行,可远程教学 欢迎下载,学习使用!
多种调度模式下的光储电站经济性最优储能容量配置分析 摘要:代码主要做的是一个光储电站经济最优储能容量配置的问题,对光储电站中储能的容量进行优化,以实现经济效益的最大化。 光储电站的调度模式选为联络线调整模式,目标函数中考虑了储能运行损耗费用,电收益、考核成本等,约束则主要是储能的运行约束,实现效果良好,具体看图。 代码非常精品,注释保姆级