How to score 100/100 on Google PageSpeed Insights

Who does not like blazing fast websites, that take no time to load and always serve great content. There are websites that have great design and content but tend to be slow due to many factors, for example loading images and other assets that are not optimized for the web.

Continue reading “How to score 100/100 on Google PageSpeed Insights”

Do you need a CDN for a blog

I find a lot of blogs use CDNs these days this made me wonder if they seriously need a CDN or is it just because they can get one. What felt weird was how personal blogs used CDN, where the content was mostly text. I believed strongly that they used CDNs because the website was powered by a heavy CMS or was served by a slow server, because of my previous experience of hosting on a slow shared hosting service and use of WordPress, thank you iPage for that experience. Now I use Digital Ocean, which offers VPS(Virtual Private Servers) called as droplet and gives you the option to choose from a wide verity of locations, so you can have a server close to you or your visitor.

It made sense to use a CDN with WordPress because of how there are too many clients sided files being loaded and it turns into an override from to infinity and beyond thanks to plugins and legacy code writing people.

What I found instead was even static sites used CDNs which was quite of a shock, because none of those sites were image heavy, they had quite lightweight client side scripts and stylesheet.

To such sites all a CDN would do would offer down time when the CDN service hit down time or had an issue with a specific instance that handled these clients files.

I wanted to research on why this was a trend and the results are quite interesting.

The reason

It is not a surprise that a lot of sites especially the new ones what to be more competitive and be part of the Alexa master race.

The main goal of these websites is to reach as wide of an audience as they can and will do anything to do so. The authors, publishers, and owners want to do any optimization in the client or server side without understanding if it is needed just because a click bait article describe to them using a CDN makes your site blazing fast while is true, it does not make the content or subject great.

In my opinion, a blog succeed when it has great content that is a good read and grows when such reads are served constantly. I think most people learn this only after a bit of an experience and will be misled and given wrong information till clickbait is the trend to get views.

I can understand a publisher’s mind they want to be out there and seen, noticed and seen some sites even personal blogs that turned completely clickbait just to gain views and immediate popularity, while other who had blogs gave up just because it got harder when it came to maintaining one and decided to shut it down when it was difficult. Yes, this is a sad reality, people give up too fast and want everything instantly.

When to use one

You might be already familiar with the concept to a CDN, if yes, then skip this if not then continue with the read.

A CDN has several servers or you can say instances in different locations and replicate the data from the provider(client) and replicate it onto those servers/instances, these serve then serve the content from the closest server to the visitor reducing the amount of latency and data travel on a given network. I have written a much [detailed post on this topic]

Example

Without a CDN

The server is in the US, the visitor is in Singapore, the visitor is served directly from the US server.

With a CDN

The server is in the US, the visitor is in Singapore, the visitor is served from the closest server which may be in Singapore or in some part of Asia, this means it is served by a server inside of Asia.

These days CDN services offer servers in many countries, letting the visitor be served by a server inside the country, for example, there can be servers in India that in both Mumbai and Delhi, so visitors of Mumbai will be served a server in Mumbai.

Do you need it?

If you have large amounts of posts or data being served and is large files or image heavy then you must go with a CDN otherwise you don’t need one if your server can handle decent traffic and the page load time is not very long

Gogs on CentOS

Gogs also known as Go Git Server is an open source cross-platform self-hosted Git server written in Golang, similar to the GitLab which is written in Ruby. It is easy to install and configure and offers a lot of customization options while installing, it lets you choose between MySQL, SQLite, and PostgreSQL as a Database backend. It is also one of the lightest and fastest self-hosted Git server solution, it does not offer a lot of features like GitLab, but whatever it offers, it does it without pain. If you don’t already have a CentOS server, you can get a VPS on Digital Ocean, by signing up with this referral you get $10 credit and I get $25 credit. Installing Gogs is easy it’s available as a pre-compiled package from Packager. It receives updates like every other package you would install on your system. So you can do the setup once and receive an update on new builds. This setup being pre-build, might not support SQLite, for this guide, I am using MariaDB. You can use PostgreSQL over MariaDB if you prefer it.

Getting started.

Adding Gogs repository key.

sudo rpm --import https://rpm.packager.io/key  

Add Gogs packager.io repository to your local packages database.

echo "[gogs]  
name=Repository for pkgr/gogs application.  
baseurl=https://rpm.packager.io/gh/pkgr/gogs/centos7/pkgr  
enabled=1" | sudo tee /etc/yum.repos.d/gogs.repo  

Installing Gogs

sudo yum install gogs  

Installing MySQL

sudo yum install mysql-server -y  

Setting up MySQL

sudo mysql_secure_installation  

Logging into MySQL console.

mysql -u root -p  

Creating a new Database for Gogs.

CREATE DATABASE gogs;  

Exiting MySQL console.

exit  

Installing NGINX to reverse proxy Gogs to port 80.

sudo rpm -Uhv http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm  


sudo yum install -y nginx  

Editing the NGINX config /etc/nginx/conf.d/default.conf

sudo nano /etc/nginx/conf.d/default.conf  

Add the following lines to your NGINX config.

server {  
listen          80;  
  server_name     ${HOSTNAME};
  location / {
    proxy_pass      http://localhost:3000;
  }
}

Restart NGINX.

sudo service nginx restart  

You can access the newly setup Gogs Server at http://127.0.0.1/, and further configure it to your preference and create your new user, you can now store your projects on your private Git server. Have a question, leave a comment below.

Gogs on Debian

Gogs also known as Go Git Server is an open source cross-platform self-hosted Git server written in Golang, similar to the GitLab which is written in Ruby. It is easy to install and configure and offers a lot of customization options while installing, it lets you choose between MySQL, SQLite, and PostgreSQL as a Database backend. It is also one of the lightest and fastest self-hosted Git server solution, it does not offer a lot of features like GitLab, but whatever it offers, it does it without pain. If you don’t already have a Debian server, you can get a VPS on Digital Ocean, by signing up with this referral you get $10 credit and I get $25 credit. Installing Gogs is easy it’s available as a pre-compiled package from Packager. It receives updates like every other package you would install on your system. So you can do the setup once and receive an update on new builds. This setup being pre-build, might not support SQLite, for this guide, I am using MariaDB. You can use PostgreSQL over MariaDB if you prefer it.

Getting started.

Adding Gogs repository key.

wget -qO - https://deb.packager.io/key | sudo apt-key add -  

Add Gogs packager.io repository to your sources.list.d directory/ For Jessie

sudo echo "deb https://deb.packager.io/gh/pkgr/gogs jessie pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list  

For Wheezy

sudo echo "deb https://deb.packager.io/gh/pkgr/gogs wheezy pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list  

Updating local package database to fetch meta of the new repository.

sudo apt-get update  

Installing Gogs

sudo apt-get install gogs  

Adding MariaDB repository, choose the setup depending on the version of Debian you are using and the closest mirror you prefer, from here.

sudo apt-get update  

Logging into MariaDB console.

mysql -u root -p  

Creating a new Database for Gogs.

CREATE DATABASE gogs;  

Exiting MySQL console.

exit  

Installing NGINX to reverse proxy Gogs to port 80.

sudo apt-get install nginx-full  

Editing the NGINX config /etc/nginx/sites-enabled/default

sudo nano /etc/nginx/sites-enabled/default  

Add the following lines to your NGINX config.

server {  
  listen          80;
  server_name     yourhostname;

  location / {
    proxy_pass      http://127.0.0.1:3000;
  }
}

Restart NGINX.

sudo service nginx restart  

You can access the newly setup Gogs Server at http://127.0.0.1/, and further configure it to your preference and create your new user, you can now store your projects on your private Git server. Have a question, leave a comment below.

When and why you should use a CDN

CDN also known as Content Delivery Network is a way to distribute web content and assets to the user depending on this geographical location, this means that the closest server to your location will serve you the content. This makes a load up time faster and reduces the load amount of active connection on the main server due to faster delivery. Here are some CDN services available Cloudflare, MaxCDN, Microsoft Azure

How CDN works

Why use CDN?

CDN deliver content faster to the user, this reduces the load up time of individual files and assets, this is achieved by having multiple copies of data distributed to servers from various locations.

Here is a simple example:

If you live in Asia and the website you are visiting is has a server located in Europe, the amount of time it would take to load up a page on the network would be longer, because of the distance between the two locations. This is not noticed when serving small files, but if you are going to download a file as big as 1GB or larger, you may notice a bit of delay before the downloader connects to the server to request the file and will have a network delay while fetching the content, this is still fine if the file you have requested is not requested by other users, but if there are a large number of people downloading the same file from the same server, it might take a longer time, because the individual server has its own limit to handle requests.

So now lets see how a CDN can help out.

A CDN will copy the same files to multiple servers located in different locations like Asia, Europe, America and depending on the user’s location, it will serve the file, So if you live in Asia, the server located in Asia will serve you the file by detecting the location, while accepting the request made by you. This reduces the delay because the distance in the network is shorter and there are multiple servers to server content based on location, so now if a visitor from Europe downloads the same file it will retrieve the file from the server located in Europe and serve it to the user. This lets websites like Google, YouTube and many other websites serve content to a larger audience from various location with a shorter delay.

But, when do I need a CDN?

When your website is large and has to serve content to a large audience of various location is a short amount of time. So if you have a blog that gets a good number of views and has graphical right content and the server can handle it without a pain and if there is no noticeable delay in content served to the user, you really don’t need a CDN. Only if you have a lot of traffic, which might delay the web content served to a large number visitors, or if you have a sudden rush of traffic to every new blog post, that can not be handled instantly by the server instantly, that is when you might need a CDN.

Everything at once

CDN are good for serving content faster to a visitor depending on their location, this is good for websites that have a large number of visitors and can have large amounts of delay, which might make them lose visitors and can crash the servers, It does not make any sense to have a CDN for a website that gets a decent amount of traffic that can be handled by the server without any pain and does not have large amount data to be served for every request

Thank you for reading,

If you have any questions feel free to leave a comment below.

The image used in the post is by Wikipedia

Transfer files using Rsync

I had been using FTP for a very long time for transferring, it is a great protocol for file transfer, but it is time-consuming when transferring big files or many files to a distant server, a server can timeout if the server is or the client network is slow.

I spend some time trying to discover alternatives. I finally discovered Rsync, a nice protocol to transfer files which were also supported by my Server/receiver where I wanted my files to be transferred.

So, I wrote this small script and thought I would share it.

rsync --compress --recursive --checksum upload_folder/ user@host.com:deploy_location/  

This is a simple and easy way to upload file, you can edit the flags according to your needs

Thank you for reading.