Several Notes on Domain Optimization Configuration for This Blog

✍🏼 Written on May 23, 2016   
❗️ Note: it has been days since this article was written, please be aware of its timeliness

Preface

When I decided to set up a static blog on GitHub Pages, my goal was to maximize its loading speed. To achieve this, I employed some minor tricks to accelerate page loading and enhance user experience.

Optimizations

Utilizing Baidu CDN and Qiniu Static Resource Hosting

This blog uses three libraries/font files: Bootstrap/jQuery/fontawsome. Since Bootstrap, I made slight modifications to better suit the layout, so I didn’t rely on third-party CDN. Instead, I hosted them on Qiniu’s resource server, while jQuery uses Baidu’s public static resource service.

Here’s a quick advertisement: For individual users, Qiniu offers 10GB of free storage after completing Alipay real-name verification. Based on my experience, the speed is decent. I pointed the domain img.xheldon.com CNAME to Qiniu’s resource server to host static assets like the customized Bootstrap and images. This way, I only need to upload files, specify the paths, and use img.xheldon.com/path/filename.ext:

Update (September 3, 2019): Since my domain is registered with GoDaddy and not filed in China (to avoid potential blocking), Qiniu cannot resolve unfiled domains. As a result, I had to store images alongside the articles, which led me to minimize image usage in posts -_-

Honestly, since this is a static blog, the Cookie carried by requests isn’t substantial. Hosting resources on a separate subdomain doesn’t make a huge difference, but every little bit helps.

Embedding Small Resources Directly in Pages

I embedded small css and js directly into the pages, such as highlight.css and search.js, using style and script tags. This approach has significant benefits because these files are tiny, and the time required to download them is negligible. If they were externally linked, the loading time would primarily be consumed by TTFB (requires VPN):

TTFB

Configuration

In my younger days, lacking experience, I directly pointed the A record of this site’s www to Github Pages’s IP 192.30.252.154/192.30.252.153, while mistakenly using CNAME to point the top-level domain @ to xheldon.github.io.. If you don’t have MX pointing to @, this setup is OK. However, since I wanted my resume to look cooler by using my blog’s domain as an email address, I opted for QQ’s domain email service. When configuring MX resolution, I needed to point the top-level domain @ to Tencent’s mxdomain.qq.com, which triggered an error. Alibaba Cloud warned that CNAME and MX cannot both point to the top-level domain @. For details, see here]. But now, months after migrating the blog, some links have already been indexed by search engines, and changing them would cause significant losses.

My initial configuration was as follows:

Record Type Host Record Record Value
CNAME @ xheldon.github.io.
A www 192.30.252.154
A www 192.30.252.153

Since I used Tencent’s domain email service, I needed to set up an MX record to @. However, MX’s @ cannot coexist with CNAME’s @. To resolve this, I considered stealth URL forwarding. I removed CNAME pointing to @, added an MX record pointing to @, and then set up a stealth URL:

Record Type Host Record Record Value
A www 192.30.252.154
A www 192.30.252.153
MX @ mxdomain.qq.com.
CNAME qqmailhash mail.qq.com.
Stealth URL @ http://www.xheldon.com

At the same time, I changed the CNAME file in the blog’s branch directory from xheldon.com to www.xheldon.com. Then I noticed that when accessing the blog via search engines, such as xheldon.com/about/, it did redirect to the blog, but only to the homepage! This means any previously indexed links by search engines would only land on the homepage www.xheldon.com. In other words, implicit forwarding only redirects specific addresses without automatically appending the path after the address. For example, in my case, after setting up an implicit URL forwarding from xheldon.com to www.xheldon.com, all requests to xheldon.com/xxxx were forwarded to www.xheldon.com instead of the expected www.xheldon.com/xxxx.

At this point dig xheldon.com:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
; <<>> DiG 9.8.3-P1 <<>> xheldon.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20871
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;xheldon.com. IN A

;; ANSWER SECTION:
xheldon.com. 585 IN A 42.156.141.13

;; Query time: 7 msec
;; SERVER: 172.168.200.110#53(172.168.200.110)
;; WHEN: Thu Mar 30 10:06:41 2017
;; MSG SIZE rcvd: 45

I noticed the top-level domain was pointing to an Alibaba Cloud IP.

So I reconsidered and modified the A record’s @, directly pointing it to GitHub Pages’s IP address. The content of the CNAME file in the blog’s root directory was updated to www.xheldon.com:

Record Type Host Record Record Value
A @ 192.30.252.154
A @ 192.30.252.153
MX @ mxdomain.qq.com
CNAME qqmailhash mail.qq.com.
CNAME www github.xheldon.com.

The reason this works is because Github Pages automatically matches ](https://help.github.com/articles/setting-up-an-apex-domain-and-www-subdomain/). To explain in detail:

  1. If the CNAME file contains www.xheldon.com, and a request comes from xheldon.com (which requires configuring the top-level domain @'s A record to point to GitHub Pages’s IP), it will forward to www.xheldon.com.
  2. If the CNAME file contains xheldon.com, and a request comes from www.xheldon.com (which requires configuring the secondary domain www’s A record to point to GitHub Pages’s IP), it will forward to xheldon.com.

At this point, dig www.xheldon.com noticed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
; <<>> DiG 9.8.3-P1 <<>> www.xheldon.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56061
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.xheldon.com. IN A

;; ANSWER SECTION:
www.xheldon.com. 600 IN CNAME xheldon.github.io.
xheldon.github.io. 3600 IN CNAME github.map.fastly.net.
github.map.fastly.net. 28 IN A 151.101.100.133

;; Query time: 178 msec
;; SERVER: 172.168.200.110#53(172.168.200.110)
;; WHEN: Thu Mar 30 10:20:30 2017
;; MSG SIZE rcvd: 115

dig xheldon.com noticed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; <<>> DiG 9.8.3-P1 <<>> xheldon.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59875
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;xheldon.com. IN A

;; ANSWER SECTION:
xheldon.com. 600 IN A 192.30.252.154
xheldon.com. 600 IN A 192.30.252.153

;; Query time: 462 msec
;; SERVER: 172.168.200.110#53(172.168.200.110)
;; WHEN: Thu Mar 30 12:32:23 2017
;; MSG SIZE rcvd: 61
- EOF -
Originally published at: Several Notes on Domain Optimization Configuration for This Blog - Xheldon Blog