Quick Optimization of CakePHP Application with YSlow
I run a busy Slovenian site featuring weather radar image on Google maps - vreme.malamalca.com . It is a simple CakePHP app which collects weather and radar data, stores it in cache and outputs it in friendly format.
Recently my site is receiving some heavy traffic due to high probability of hail storms which are result of high temperatures - around 35° (95°F). Everyone wants to check if their car /or home/ is in immediate danger. Bad weather is causing high spikes of traffic and sluggish response times.
After checking my site with YSlow, it got "F" grade. My site needed some improvements. There are some steps I took which got my site to grade "B" of YSlow:
- I changed my cache engine to APC. This had a tremendous effect in responsiveness of my app (although it is not graded by YSlow)
- Next step was implementation of some Apache directives in .htacces in /webroot folder:
Here are new .htaccess contents:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
# compress content with type html, text, and css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#AddOutputFilter DEFLATE js css
# properly handle requests coming from behind proxies
Header append Vary User-Agent
ExpiresActive On
ExpiresByType application/javascript "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/js "access plus 10 years"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
FileETag none
These adjustments made my site usable again even in spikes of 500 users per minute.
Note: some aditional warnings... this directives extend duration of cached items in your browser. You should know what are you trying to achieve.
Comments