Before describing the manipulation to be done to accelerate the speed of your site and reduce loading times, we want to clarify that some of these tips work well for sites that are not under WordPress.
Google said that the speed of page loading was a factor to consider in the SEO, then we should better optimize it.
Open to edit your .Htaccess file (take a backup first). For us, using online FTP works great to do the job. Add the following codes to your .Htaccess file before the starting of your WordPress rewrite rules:
---
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|xml|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule> # END GZIP # DEFLATE compression <IfModule mod_deflate.c> # Set compression for: html,txt,xml,js,css AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript # Deactivate compression for buggy browsers BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch bMSIE !no-gzip !gzip-only-text/html # Set header information for proxies Header append Vary User-Agent </IfModule> # END DEFLATE <FilesMatch ".js$"> AddHandler application/x-httpd-php .js php_value default_mimetype "text/javascript" </FilesMatch> <FilesMatch ".css$"> AddHandler application/x-httpd-php .css php_value default_mimetype "text/css" </FilesMatch> <FilesMatch ".(htm|html|shtml)$"> AddHandler application/x-httpd-php .html php_value default_mimetype "text/html" </FilesMatch> ## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" 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" ExpiresDefault "access 2 days" </IfModule> ## EXPIRES CACHING ## <ifModule mod_headers.c> <filesMatch "\.(ico|pdf|flv|jpg|jpeg|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 "\.(xml|txt)$"> Header set Cache-Control "max-age=216000, public, must-revalidate" </filesMatch> <filesMatch "\.(html|htm|php)$"> Header set Cache-Control "max-age=300, private, must-revalidate" </filesMatch> </ifModule> |
Update: Unfortunately, the if module syntax is not showing up properly. So, here is the file for you, just click to open it.
In case mess up, just delete the codes and save it or replace with your backup file.
You can read this interesting and useful topic to optimize the pageload speed from Yahoo. It really nicely written. You can implement PHP buffer flush to load very quickly. We used both of this methods to make this website load faster. For implementing PHP buffer flush; add this in your header . php ( just after closing of head tag) file via Theme editor:
1 | //<?php flush(); ?> |
Remove the commenting ( // before < ) to get working php. This will decrease the waiting time (particularly if the server is long away from the visitor) with a blank screen on browser waiting for full page to load.
This article was written about 10 months ago, do the techniques described still work? Thanks.
Yes, these are basics and will work forever for Apache web server.
Thank you for your quick reply, how about on a light speed server?
Since LiteSpeed claims to have compatibility with Apache, it should work. LiteSpeed will follow `mod_rewrite` rules the same way as Apache2.