Cliche but important: optimise your website

Bits busy for those couple days, specially for optimise the E-commerce site which had order row over 450,000 and 6 years customers orders, it is time to optimise the site (opps, would it be too late?)

So today I will try to go through how to optimise a website(E-commerce)

For performance part, I think you guys pretty much know that you could go through follow:
1. Reduced image size, by base64, spirit Image or compressing image

2. Try minify the css, js part, if your site css using Less, Scss, Sass then you could ignore minify part, for Js it will more
be complex, try minify js, or if you write TypeScript or Babel then awesome you could ignore this part

3. Use Cachable for your page files, and the catch html content by desktop or mobile version, there’s some way to do those

4. using optimization rules in .htaccess file
The .htaccess file handles the way your web servers process your site with a lot of rules to improve your site speed
and with ETag, Expires headers, AddOutputFilterByType DEFLATE etc, follow is the simple:

########## Begin - ETag Optimization
## This rule will create an ETag for files based only on the modification
## timestamp and their size. 
## Note: It may cause problems on your server and you may need to remove it
FileETag MTime Size
# AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the future.
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
# Enable expiration control
ExpiresActive On
# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"
# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"
# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/svg+xml "now plus 1 month"
ExpiresByType image/tiff "now plus 1 month"
ExpiresByType image/ "now plus 1 month"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/ico "now plus 1 month"
ExpiresByType image/icon "now plus 1 month"
ExpiresByType text/ico "now plus 1 month"
ExpiresByType application/ico "now plus 1 month"
ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
ExpiresByType application/vnd.wap.wbxml "now plus 1 month"
ExpiresByType application/smil "now plus 1 month"
# Audio files expiration: 1 month after request
ExpiresByType audio/basic "now plus 1 month"
ExpiresByType audio/mid "now plus 1 month"
ExpiresByType audio/midi "now plus 1 month"
ExpiresByType audio/mpeg "now plus 1 month"
ExpiresByType audio/x-aiff "now plus 1 month"
ExpiresByType audio/x-mpegurl "now plus 1 month"
ExpiresByType audio/x-pn-realaudio "now plus 1 month"
ExpiresByType audio/x-wav "now plus 1 month"
# Movie files expiration: 1 month after request
ExpiresByType application/x-shockwave-flash "now plus 1 month"
ExpiresByType x-world/x-vrml "now plus 1 month"
ExpiresByType video/x-msvideo "now plus 1 month"
ExpiresByType video/mpeg "now plus 1 month"
ExpiresByType video/mp4 "now plus 1 month"
ExpiresByType video/quicktime "now plus 1 month"
ExpiresByType video/x-la-asf "now plus 1 month"
ExpiresByType video/x-ms-asf "now plus 1 month"

5. use CDN to load media:
CDN stands for content delivery network, it is an interconnected system of cache servers that use geographical proximity as a criteria for delivering Web content.
CDN is especially well suited for delivering media such as: video, audio, images, etc. So instead of loading those media from server, it loads from CDN, it’s more efficient and reliable.
For CDN, you could apply from your host server or of you have CMS website there’s nice plugin to help you quickly

6. choosing good web hosting

There’s lot choice and here has list you could take reference, for my cas I’m using Dedicated server┬áCentOS Linux which has memory 63 Go, and I use Plesk allow setting your customise php configuration and that could be more flexible then web hosting

Also if you need to reduced Mysql resource running in memory rather than disk (which will run query faster), if you have dedicated serveur then this is the part you could do it

For request query part, this will be more complicated, you had to deal with your database Optimizing Queries with EXPLAIN or Indexes

As for myself understanding, Indexes is just like a book index, that tell you where you could find the chapter or some point articles, and in your database schema, there should be have some part point to help filtre more faster

For example if you do have more then 100,000 rows in table called #orders_list , it will be get very slow to request query to select (read) one of the order list, so you need index to separate those data structure of your table and help query to find out the right information more faster

sample to create index

As you need to find the table called user which has Name, age and address columns, there’s 2000 rows

and you are write a query to find a user name ‘Tess’:

WHERE Name = 'Tess'

As there’s 2000 row, the query had to look at every single row and it will take long time, so now you could create a index to get faster:

CREATE INDEX name_index
ON User (Name)

So instead of search all columns Name, age and address, this will allow query search of User name by sorted alphabetically, in this case it will be more faster to get result

7 repaire or optimise your table database

If you use mysql, you could easily to optimise your table database just after selecting the table and click to choose optimise your table:

8. Try to test your web site through some site

and there’s so many way to reduced your website size and get your performance better, it might take lots of work but it will really worth it cause every second as count by user