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/vnd.microsoft.icon "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’:

SELECT * FROM User 
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

https://tools.pingdom.com/

https://smallseotools.com/website-page-size-checker/

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

 

 

 

5 Mistakes Web Developers Make When Working with MongoDB

downloadMongoDB has founded in 2007, until now it has more than 15 million downloads, it was really tread as cloud server make a prior choice by big data company. And you could build big data very fast by MongoDB, why MongoDB? how it does work? when it has became certain issue to pay attention with? Let’s try to get into the story!!

why MongoDB?


MongoDB is NoSQL database, NoSQL == Not Only SQL, the data structure is combined with key\value, like Json, the data type could be diver compare Relation DataBase, this is very flexible, but flexible could be disaster if not defined, organize data type efficiently!! As follow are couple reasons good for use MongoDB:

  1. For whom are front-end developer, this is much easier to learn then mysql, the MongoDB base language is Javasript & JSON
  2. MongoDB is for big data, you could de-normalize and flatten 6 tables into just 2 tables.
  3. MongoDB is Document based, if you have a tons of a single type of documents, then use Mongo

how it does work?


Install MongoDB

  1. download from https://www.mongodb.com/download-center#community1
  2. De-zip your MongoDB
  3. Create file for database, for example: Data/mydb
    2
  4. open cmd, to MongoDB path, $ mongod –dbpath ../data/mydb
  5. $ mongo , to check if it does work 4
  6. 4
  7. $ show dbs, then here you could see 2 data base are admin, local44
  8. And if you need to show down server, it has to excuse this $ db.shutdownServer(), this is important incase memory not leased, or sync up, destroyed

MongoDB basic usage


This part will show basic usage insert document, remove document, drop collection

1. insert, use cmd call out which db you want to insert, here is employee for example, insert name, account, country. and finally the data show as json:

44

2. Remove document

db.collection.remove({ condition }), justOne)

justOne: true | false, set if just remove the first data

if you want remove all: db.employee.remove({})

3. Drop document

db.collection.drop()

The rest usage please look at mangoDB tutorial

when it has became certain issue to pay attention with?


there’s some points that you should avoid when use MongoDB

  1. No easy change other DB : When you choice MongoDB, this is not like other RDBMS ———-SQL, all NoSQL has it’s own API, if you had choice it, it won’t be easier to change another DB, example change MongoDB to Couchbase.
  2. Not support ACID: ACID is the basic item of Transaction, but most NoSQL DB not quarante ACID, you need more technical skill to practice this part
  3. Not support JOIN: because NoSQL DB is Non-relational, so it does not support JOIN. use MongoDB, it has to well-orientation Data Model in the first beginning, and you could use index and Aggregation to improve the filter performance.
  4. Document limited: not like RDBMS stock data in row, MongoDB stock data in document, these documents like JSON format. therefore has limited data size, the latest had supported to 16M. So you had to be careful not over to 16M.
  5. Filter search has to define correctly lowercase/uppercase, for example: db.people.find({name: ‘Russell’}) and db.people.find({name: ‘ russell’}) is different. you could filter by regex: db.people.find({name:/Russell/i}), but this will affected the performance.

Voila, this article is very primary presentation for MongoDB, just little mind sharing as first use of mangoDB.