radoslav68
Active Member
Hello fellows!
I'm writing this thread because a week ago I had to optimize my website after receiving 4 mails by my hosting company. They were about over usage of the server CPU. I've spent a few days on researching and I got some satisfaction from the results. My website now loads faster and this is thanks to a few optimizations on the server - Apache 2.0 - 2.2, Linux OZ.
All the steps are described below and they will save you from your future problems with bad hosting services. Your site will load faster too. I use the most effective basics and the thread is oriented to shared hosting users. You will need no more than 15 minutes.
First you have to test your page's loading speed with one of these tools:
Yahoo YSlow
Google Page Speed Insight
GTmetrix
Lets get going!
Open your .htaccess file with any text editor - don't forget to create a copy in case something bad happens!
1. Enable file compression
Mod_deflate lets you compress your files. Find <ifmodule mod_deflate.c> .htaccess and replace it with this code:
In cPanel find "Programs and additional software" or something and chose the option "Optimize Website". After that click on "compress all content" Refer to the screenshots below.
Виж файлът 6034Виж файлът 6035
2. Turn on the mod_expires Apache module.
I've tested at least 10 variations, but this one gave me the best results.
Repeplace this code with the code below in the .htaccess file.
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</ifmodule>
with the code below in the .htaccess file.
3. Turn on the KeepAlives option. This increases the speed of loading of HTML pages with a lot of images.
A few more tips. Ask the support of the hosting to install you a PHP accelerator like APC or XCache. I don't need to use any of them but keep it in mind.
Do a few test with the tools mentioned above and I hope you'll see better results.
I'm writing this thread because a week ago I had to optimize my website after receiving 4 mails by my hosting company. They were about over usage of the server CPU. I've spent a few days on researching and I got some satisfaction from the results. My website now loads faster and this is thanks to a few optimizations on the server - Apache 2.0 - 2.2, Linux OZ.
All the steps are described below and they will save you from your future problems with bad hosting services. Your site will load faster too. I use the most effective basics and the thread is oriented to shared hosting users. You will need no more than 15 minutes.
First you have to test your page's loading speed with one of these tools:
Yahoo YSlow
Google Page Speed Insight
GTmetrix
Lets get going!
Open your .htaccess file with any text editor - don't forget to create a copy in case something bad happens!
1. Enable file compression
Mod_deflate lets you compress your files. Find <ifmodule mod_deflate.c> .htaccess and replace it with this code:
Код:
<ifmodule mod_deflate.c>
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</ifmodule>
In cPanel find "Programs and additional software" or something and chose the option "Optimize Website". After that click on "compress all content" Refer to the screenshots below.
Виж файлът 6034Виж файлът 6035
2. Turn on the mod_expires Apache module.
I've tested at least 10 variations, but this one gave me the best results.
Repeplace this code with the code below in the .htaccess file.
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</ifmodule>
with the code below in the .htaccess file.
Код:
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "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"
</IfModule>
# Set Expires Headers
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "public"
Header set Expires "Tue, 14 Aug 2020 03:00:00 PST"
</FilesMatch>
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
Header set Last-Modified "Mon, 31 Jan 2011 00:00:00 GMT"
</FilesMatch>
# Set the cache-control max-age
# 1 year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|js|css)$">
Header set Cache-Control "max-age=604800, public, must-revalidate"
</FilesMatch>
# 4 HOURS
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</FilesMatch>
3. Turn on the KeepAlives option. This increases the speed of loading of HTML pages with a lot of images.
Код:
KeepAlive On
KeepAliveTimeout 2
A few more tips. Ask the support of the hosting to install you a PHP accelerator like APC or XCache. I don't need to use any of them but keep it in mind.
Do a few test with the tools mentioned above and I hope you'll see better results.
Прикачени файлове
Последно редактирано от модератор: