- 浏览: 140514 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (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.
相关推荐
tables-3.6.1-cp39-cp39-win_amd64.whl
基于springboot大学生心理咨询平台源码数据库文档.zip
基于Java web 实现的仓库管理系统源码,适用于初学者了解Java web的开发过程以及仓库管理系统的实现。
基于springboot智能推荐旅游平台源码数据库文档.zip
内容概要:本文是一份详尽的Ruby语言教程,首先介绍了Ruby语言的基本信息和发展背景。接着详细讲解了Ruby的基础语法,如变量、数据类型、运算符、控制流等,并深入探讨了面向对象编程的关键概念,包括类、对象、继承、封装和多态。随后介绍了Ruby的一些高级特性,如模块、异常处理、迭代器和文件I/O操作。最后,讨论了Ruby在Web开发中的应用,尤其是与Rails框架的结合。每个部分都配有相应的代码示例,帮助读者更好地理解和实践。 适合人群:适用于初学者和有一定基础的程序员,特别是对Ruby语言感兴趣的人。 使用场景及目标:学习和掌握Ruby语言的各项基础知识和高级特性,为进一步进行Web开发或其他相关编程打下坚实的基础。 其他说明:教程中的每一部分内容都有详细的解释和代码示例,非常适合自学和教学使用。
GEE训练教程——Landsat5、8和Sentinel-2、DEM和各2哦想指数下载
基于springboot在线问诊系统源码数据库文档.zip
基于springboot的流浪猫狗救助系统源码数据库文档.zip
GEE训练教程
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
本教程帮助您了解什么是 SQLite,它与 SQL 之间的不同,为什么需要它,以及它的应用程序数据库处理方式。需要的朋友们可以参考看看! SQLite是一个软件库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。SQLite是一个增长最快的数据库引擎,这是在普及方面的增长,与它的尺寸大小无关。SQLite 源代码不受版权限制。 什么是 SQLite? SQLite是一个进程内的库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。它是一个零配置的数据库,这意味着与其他数据库一样,您不需要在系统中配置。 就像其他数据库,SQLite 引擎不是一个独立的进程,可以按应用程序需求进行静态或动态连接。SQLite 直接访问其存储文件。 为什么要用 SQLite? 不需要一个单独的服务器进程或操作的系统(无服务器的)。 SQLite 不需要配置,这意味着不需要安装或管理。 一个完整的 SQLite 数据库是存储在一个单一的跨平台的磁盘文件。 SQLite 是非常小的,是轻量级的,完全配置时小于 400KiB,省略可选功能配置时小于250K
基于springboot学生选课系统源码数据库文档.zip
【Android UI】SurfaceView中使用 Canvas 绘制可缩放大图 ( 拖动和缩放相关的变量 | Canvas 绘图函数 | 手势识别 多点触控流程 | 拖动图片 | 缩放图片 ) 博客链接:https://blog.csdn.net/shulianghan/article/details/143950948 一、需求分析 和 核心要点 说明 1、需求说明 2、核心要点 - 拖动和缩放相关的变量 3、核心要点 - Canvas 绘图函数 4、核心要点 - 手势识别 多点触控流程 5、核心要点 - 拖动图片 6、核心要点 - 缩放图片 二、完整代码示例 1、环境说明 2、SurfaceView 完整代码 3、运行结果
基于springboot+web的二手闲置交易系统源码数据库文档.zip
GEE训练教程
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
基于SpringBoot的宠物寄领养网站源码数据库文档.zip
基于springboot的电影院售票管理系统源码数据库文档.zip
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
数据存放网盘,txt文件内包含下载链接及提取码,永久有效。失效会第一时间进行补充。样例数据及详细介绍参见文章:https://blog.csdn.net/T0620514/article/details/143956923