PDA

View Full Version : How To Increase Your Loading Speed



seekyt
09-15-2010, 05:31 PM
This is a simple, newbie friendly way to improve your loading times if you have concerns about your page speed. I learned this on the pligg forums a few months ago, and copied it straight over to here, so I don't deserve any credit for this.

This improved my loading time from 3.5 seconds to 0.85 seconds according to the Google Page Speed test.

Copy and paste this to the end of your .htaccess file. This will start compressing text files and images(if you use any), expiring headers, controlling the cache rate, etc. I did not include the gzip file compression code here because gzip interferes with a lot of the javascript that I used to use on pligg, and I don't want to take a chance with it interfering here (specifically, with the "post images" plugin - used to make a similar pligg module fail to load images).


# BEGIN Compress text files
<IfModule mod_deflate.c>
<FilesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
# END Compress text files
# BEGIN Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
# END Expire headers
# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
</IfModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
# END Turn ETags Off
# BEGIN Remove Last-Modified Header
<IfModule mod_headers.c>
Header unset Last-Modified
</IfModule>
# END Remove Last-Modified Header


If this causes you any problems, just go back and delete it from your .htaccess file. It is working smoothly with my Hotaru install, so I don't see why it wouldn't work with your own.

richrf
09-15-2010, 10:07 PM
Hi,

Thanks for the tip. Since I do not understand htaccess coding, can you explain what this piece of code is doing? Is it clashing with Hotaru's cache? I wouldn't want old data to be cached when it should be being refreshed.

Thanks much.

Rich

JonH
09-16-2010, 03:12 AM
That code was borrowed from here (http://www.samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/)

It deals with your browsers cache so I don't think it will effect Hotaru's caching. Hmm second thought not sure since there's php extensions mentioned too :confused:

You can also learn more about it here (http://developer.yahoo.com/performance/)

petsagouris
09-16-2010, 06:26 AM
Since this is not Hotaru related but relates to server configuration, I am moving this thread to the "Other" forum category.

seekyt
09-16-2010, 05:35 PM
Sorry for the incorrect category!

I am not receiving any errors or any other technical issues from this .htaccess addon. To be completely honest, I am not sure that I totally understand what actually "happens" when you add this extension, I just know that it works.

<off topic>For a custom plugin/pligg module I am working on, I have to use a more sophisticated extension that really starts to mess with things bad - i.e., in Pligg, a new header expiration code/cookie assignment code made it impossible for me to edit posts, disabled custom avatars, etc. If I manage to convince the developer I'm working with to switch over to hotaru for the development of this program, I will share more details in a later post.</off topic>

Anyway, all I really know about this extension is that it works for me and doesn't cause me any technical issues, so I figured I'd share it in case anyone else can elaborate on it, make it better, or learn from it.

kmai
09-16-2010, 07:52 PM
Look here (http://pligg-template.com/speed-up-pligg-loading-times-by-using-htaccess-rules-01212010/)


I did not include the gzip file compression code here because gzip interferes with a lot of the javascript that I used to use on pligg, and I don't want to take a chance with it interfering here (specifically, with the "post images" plugin - used to make a similar pligg module fail to load images).

If you had any doubts


It deals with your browsers cache so I don't think it will effect Hotaru's caching. Hmm second thought not sure since there's php extensions mentioned too

If you do not use compression to remove the lines below
it is who makes the compression


# BEGIN Compress text files
<IfModule mod_deflate.c>
<FilesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
# END Compress text files

Apache 2x up now to use the mod_deflate
mod_gzip in apache was used until 1x

I use compression with no problems