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):

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 | |
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:
- If the
CNAMEfile containswww.xheldon.com, and a request comes fromxheldon.com(which requires configuring the top-level domain@'sArecord to point toGitHub Pages’sIP), it will forward towww.xheldon.com. - If the
CNAMEfile containsxheldon.com, and a request comes fromwww.xheldon.com(which requires configuring the secondary domainwww’sArecord to point toGitHub Pages’sIP), it will forward toxheldon.com.
At this point, dig www.xheldon.com noticed:
1 | |
dig xheldon.com noticed:
1 | |
I often wish that when facing some key decisions in life, someone could tell me the best course of action so that I would not waste my precious time. Putting myself in others' shoes, I therefore write blogs often, hoping to record in this tiny corner of the vast Internet the once-in-a-lifetime experiences that matter to me, and to help those who seek help.